相关疑难解决方法(0)

Python:检查'Dictionary'是否为空似乎不起作用

我正在尝试检查字典是否为空但它的行为不正常.除了显示消息之外,它只是跳过它并显示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)

python dictionary

337
推荐指数
6
解决办法
47万
查看次数

标签 统计

dictionary ×1

python ×1