[英]Python None check (redis)
我正在使用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值,但是它不起作用,即使結果為None,我也從未輸入過else循環。 輸出:
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']
我可能錯過了一些東西,但我不知道。
>>> [None] is None
False
是您問題的答案。 嘗試將您的條件更改為:
if get_result[0]:
# there are results
else:
# there are no results
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.