最佳答案
我试图检查字典是否为空,但它不能正常工作。它只是跳过它并显示在线,除了显示消息之外没有任何内容。知道为什么吗?
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()))