我正在尝试检查字典是否为空,但是行为不正常。 它只是跳过它并显示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()))    

===============>>#1 票数:865 已采纳

我正在尝试检查字典是否为空,但是行为不正常。 它只是跳过它并显示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()))    

===============>>#2 票数:156

我正在尝试检查字典是否为空,但是行为不正常。 它只是跳过它并显示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()))    

===============>>#3 票数:19

我正在尝试检查字典是否为空,但是行为不正常。 它只是跳过它并显示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()))    

===============>>#4 票数:14

我正在尝试检查字典是否为空,但是行为不正常。 它只是跳过它并显示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()))    

===============>>#5 票数:3

我正在尝试检查字典是否为空,但是行为不正常。 它只是跳过它并显示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()))    

===============>>#6 票数:0

我正在尝试检查字典是否为空,但是行为不正常。 它只是跳过它并显示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()))    

===============>>#7 票数:0

Python 3:

def is_empty(dict):
   if not bool(dict):
      return True
   return False

test_dict = {}
if is_empty(test_dict):
    print("1")

test_dict = {"a":123}
if not is_empty(test_dict):
    print("1")

===============>>#8 票数:-1

我正在尝试检查字典是否为空,但是行为不正常。 它只是跳过它并显示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()))    

===============>>#9 票数:-4

为什么不使用平等测试?

def is_empty(my_dict):
    """
    Print true if given dictionary is empty
    """
    if my_dict == {}:
        print("Dict is empty !")

===============>>#10 票数:-9

我正在尝试检查字典是否为空,但是行为不正常。 它只是跳过它并显示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()))    

  ask by Unsparing translate from so

未解决问题?本站智能推荐: