반응형
사전이 비어 있는지 확인하려고하는데 제대로 작동하지 않습니다. 그냥 건너 뛰고 메시지 표시를 제외하고는 아무것도없이 온라인 을 표시합니다. 이유는 무엇입니까?
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()))
해결 방법
>>> dct = {}
>>> bool(dct)
False
>>> not dct
True
>>>
따라서 isEmpty
함수가 필요하지 않습니다. 당신이해야 할 일은 :
def onMessage(self, socket, message):
if not self.users:
socket.send("Nobody is online, please use REGISTER command" " in order to register into the server")
else:
socket.send("ONLINE " + ' ' .join(self.users.keys()))
참조 페이지 https://stackoverflow.com/questions/23177439
반응형
'파이썬' 카테고리의 다른 글
파이썬에서 행렬 열 합계 (0) | 2020.12.15 |
---|---|
파이썬에서 두 개의 목록을 수학적으로 빼는 방법은 무엇입니까? (0) | 2020.12.15 |
파이썬 Getting min and max Dates from a pandas dataframe (0) | 2020.12.15 |
파이썬 동일한 컴퓨터에서 두 개의 웹 서버를 실행할 수 있습니까? (0) | 2020.12.15 |
파이썬 Python | change text color in shell (0) | 2020.12.15 |
댓글