以 10 为底数的 int() 无效文字 Python

invalid literal for int() with base 10 Python

上面的错误代码如下:

import optparse
import socket
from socket import *
from threading import *


def main():
    parser =optparse.OptionParser('usage%prog -H <target host> -p <target port>')
    parser.add_option('-p',dest='tgtPort',type='string',help='specific target port separated by comma')
    (options, args) = parser.parse_args()

    tgtPorts = str(options.tgtPort).split(', ')
    for p in tgtPorts:
        print int(p)


if  __name__ == '__main__':
    main()

当我尝试实施时:

python testInt.py -p 20, 80

预期结果:

20 80 

嗯,当你打电话时

python testInt.py -p 20, 80

20, 传递给 -p 参数,80 包含在其余参数中。

您需要将它们用引号引起来才能正常工作

python testInt.py -p "20, 80"