Python 2.7 - Error at line 298 - What is wrong with my code? [closed]
Here is the code from the last if: to the next if:
if msgtype == "\x00":
utflength=struct.unpack("!h", data[:2])[0]
name=str(data[2:int(utflength)+2])
data=data[utflength+2:]
utflength=struct.unpack("!h", data[:2])[0]
message=data[2:utflength+2]
self.sendOutput("To " + name + ": " + message)
else:
utflength=struct.unpack("!h", data[:2])[0]
name=str(data[2:int(utflength)+2])
data=data[utflength+2:]
utflength=struct.unpack("!h", data[:2])[0]
message=data[2:utflength+2]
self.sendOutput("From " + name + ": " + message)
else:
utflength=struct.unpack("!h", data[:2])[0]
name=str(data[2:int(utflength)+2])
data=data[utflength+2:]
utflength=struct.unpack("!h", data[:2])[0]
message=data[2:utflength+2]
self.sendOutput("From " + name + ": " + message)
There can only be one else
per if
statement.
You can, however, distinguish different cases with elif
:
if condition1:
...
elif condition2:
assert not condition1
...
else:
assert not condition1 and not condition2
...
For details on if
, else
, elif
, and other flow control statements, refer to the Python documentation.
精彩评论