开发者

Python 2.7 - Error at line 298 - What is wrong with my code? [closed]

It's difficult to tell what is开发者_如何学JAVA being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜