Python getopt 行为

Python getopt behavior

#!/usr/bin/python
import sys
import getopt

o, a = getopt.getopt(sys.argv[1:], 'ab:c:')

print "options: %s" % (o)
print "arguments: %s" % (a)

运行 python:

python TestOpt.py a b 10 c 20

它打印出来是这样的:

options: []
arguments: ['a', 'b', '10', 'c', '20']

我不明白为什么选项是一个空列表而参数看起来像选项?

试试:

python TestOpt.py -a -b 10 -c 20 foobar