SyntaxError: invalid syntax after Cast a string to int
SyntaxError: invalid syntax after Cast a string to int
我在 python 中写了一段代码,当我让它 运行 时,我收到以下消息:
File "port.py", line 229
port = (int) a
^
SyntaxError: invalid syntax
由于代码有点长,下面只给出重要的部分:
try:
opts, args = getopt.getopt(sys.argv[1:], 'hle:t:p:cu:',
['help','listen','execute', 'target',
'port', 'command', 'upload'])
except getopt.GetoptError as err:
print(str(err))
usage()
for o,a in opts:
if o in ('-h', '--help'):
usage()
elif o in ('-l','--listen'):
listen = True
elif o in ('-e', '--execute'):
execute = a
elif o in ('-c','--commandshell'):
command = True
elif o in ('-u','--upload'):
upload_destination = a
elif o in ('-t','--target'):
target = a
elif o in ('-p','--port'):
port = (int) a
else:
assert False,'Unhandled Option'
所以,a应该是字符串类型的端口号。所以,我认为我应该施放它。
python的版本是2.7.3。
我不明白为什么会出现错误消息。我希望有人能提供帮助。
此致,
要从字符串 a
创建新的 int
对象,请使用
port = int(a)
我在 python 中写了一段代码,当我让它 运行 时,我收到以下消息:
File "port.py", line 229
port = (int) a
^
SyntaxError: invalid syntax
由于代码有点长,下面只给出重要的部分:
try:
opts, args = getopt.getopt(sys.argv[1:], 'hle:t:p:cu:',
['help','listen','execute', 'target',
'port', 'command', 'upload'])
except getopt.GetoptError as err:
print(str(err))
usage()
for o,a in opts:
if o in ('-h', '--help'):
usage()
elif o in ('-l','--listen'):
listen = True
elif o in ('-e', '--execute'):
execute = a
elif o in ('-c','--commandshell'):
command = True
elif o in ('-u','--upload'):
upload_destination = a
elif o in ('-t','--target'):
target = a
elif o in ('-p','--port'):
port = (int) a
else:
assert False,'Unhandled Option'
所以,a应该是字符串类型的端口号。所以,我认为我应该施放它。
python的版本是2.7.3。
我不明白为什么会出现错误消息。我希望有人能提供帮助。
此致,
要从字符串 a
创建新的 int
对象,请使用
port = int(a)