Indentation-Error 正在发生,我似乎看不出是什么导致了错误
Indentation-Error is occurring and i can't seem to see what is making the error
我正在尝试进行实时聊天,完成后我收到缩进错误,下面的代码是根据 python.
出现错误的地方
def recevied_message_from_server(self, so):
while True:
Buffer = so.recv(256)
if not buffer:
break
message = buffer.decode('utf-8')
if "joined" in message:
user = message.split(": ")[1]
message = user + " has joined"
self.chat_area.insert('end', message + '\n')
self.chat_area.yview(END)
else:
self.chat_area.insert('end', message + '\n')
self.chat_area.yview(END)
so.close()
while 循环后的空格数不一致,这是不允许的。 :
def recevied_message_from_server(self, so):
while True:
Buffer = so.recv(256)
if not buffer:
break
message = buffer.decode('utf-8')
if "joined" in message:
user = message.split(": ")[1]
message = user + " has joined"
self.chat_area.insert('end', message + '\n')
self.chat_area.yview(END)
else:
self.chat_area.insert('end', message + '\n')
self.chat_area.yview(END)
so.close()
这里要注意两点:
- 在
break
语句之后,缩进有点偏离
- 混合了 2 个和 4 个空格
检查下面提到的编辑功能一次以供参考:
def recevied_message_from_server(self, so):
while True:
Buffer = so.recv(256)
if not buffer:
break
message = buffer.decode('utf-8')
if "joined" in message:
user = message.split(": ")[1]
message = user + " has joined"
self.chat_area.insert('end', message + '\n')
self.chat_area.yview(END)
else:
self.chat_area.insert('end', message + '\n')
self.chat_area.yview(END)
so.close()
我正在尝试进行实时聊天,完成后我收到缩进错误,下面的代码是根据 python.
出现错误的地方 def recevied_message_from_server(self, so):
while True:
Buffer = so.recv(256)
if not buffer:
break
message = buffer.decode('utf-8')
if "joined" in message:
user = message.split(": ")[1]
message = user + " has joined"
self.chat_area.insert('end', message + '\n')
self.chat_area.yview(END)
else:
self.chat_area.insert('end', message + '\n')
self.chat_area.yview(END)
so.close()
while 循环后的空格数不一致,这是不允许的。 :
def recevied_message_from_server(self, so):
while True:
Buffer = so.recv(256)
if not buffer:
break
message = buffer.decode('utf-8')
if "joined" in message:
user = message.split(": ")[1]
message = user + " has joined"
self.chat_area.insert('end', message + '\n')
self.chat_area.yview(END)
else:
self.chat_area.insert('end', message + '\n')
self.chat_area.yview(END)
so.close()
这里要注意两点:
- 在
break
语句之后,缩进有点偏离 - 混合了 2 个和 4 个空格
检查下面提到的编辑功能一次以供参考:
def recevied_message_from_server(self, so):
while True:
Buffer = so.recv(256)
if not buffer:
break
message = buffer.decode('utf-8')
if "joined" in message:
user = message.split(": ")[1]
message = user + " has joined"
self.chat_area.insert('end', message + '\n')
self.chat_area.yview(END)
else:
self.chat_area.insert('end', message + '\n')
self.chat_area.yview(END)
so.close()