我试图使用python的getopt来解析一些输入参数,但是我的选项没有被识别。为什么会发生以下情况?我做错什么了?你知道吗
>> $ ipython
Python 2.7.6 (default, Nov 23 2017, 15:49:48)
Type "copyright", "credits" or "license" for more information.
IPython 1.2.1 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: import getopt
In [2]: opts, args = getopt.getopt(['arg1', '-f', '-l'], "filo:t:", ["help", "output="])
In [3]: opts
Out[3]: []
In [4]: args
Out[4]: ['arg1', '-f', '-l']
根据[Python]: getopt.getopt(args, options[, long_options]):
'arg1'
就是这样一个非选项参数。将其放在列表的末尾(2nd调用),将产生预期的输出:来自同一页(也有@tripleee的建议):
相关问题 更多 >
编程相关推荐