我想创建一个function()
,其任务是将sAMAccountName
变量的值与排除模式文件中存储的值进行比较。要检查的值是使用for loop
从encoded_users_from_LDAP.json
文件中获取的,模式文件为addc_accounts_excluded.json
。在主循环中,我想放置条件if is_account_excluded(sAMAccountName) == False:
我代码的一部分:
with open("addc_accounts_excluded.json", 'r', encoding="UTF-8") as file:
data = json.load(file)
excluded_users = data['sAMAccountName']
with open("encoded_users_from_LDAP.json", 'r', encoding="UTF-8") as file:
data = json.load(file)
retrived_users = data['entries']
def is_account_excluded(): # this what I need to validate accounts
for user in retrived_users:
attributes = user['attributes']
sAMAccountName = attributes['sAMAccountName']
if is_account_excluded(sAMAccountName) == False:
print(sAMAccountName)
print(attributes['cn'])
编辑:我设法解决了这个问题,它工作,但我不知道它是否写正确
def is_account_excluded(suspect):
account = False
for account_checked in excluded_users:
if (account_checked == suspect):
account = True
return account
1条答案
按热度按时间nvbavucw1#
如果我对你的问题的理解是正确的,这应该工作: