我使用redis-py编写模块, 我有一个问题:
def get_users_from_usergroup(usergroup):
get_result = r_server.hmget('usergroups', usergroup)
if get_result is not None:
print('users from the given usegroup [' + usergroup + '] are :')
print(get_result)
return (get_result)
else:
print("Usergroup not found")
return "error"
我检查了None值,但它没有工作我从不进入else循环,即使结果为None。 输出:
users from the given usegroup [random] are :
[None]
users from the given usegroup [random] are :
[None]
users from the given usegroup [random] are :
['as872 bs940 e0286']
我可能错过了一些东西,但我不知道是什么。
答案 0 :(得分:1)
>>> [None] is None
False
是您问题的答案。尝试将您的条件更改为:
if get_result[0]:
# there are results
else:
# there are no results