我正在尝试检查字典是否为空但它的行为不正常.除了显示消息之外,它只是跳过它并显示ONLINE而没有任何内容.有什么想法吗?
def isEmpty(self, dictionary):
for element in dictionary:
if element:
return True
return False
def onMessage(self, socket, message):
if self.isEmpty(self.users) == False:
socket.send("Nobody is online, please use REGISTER command" \
" in order to register into the server")
else:
socket.send("ONLINE " + ' ' .join(self.users.keys()))
Run Code Online (Sandbox Code Playgroud)