當我指定一個命令行選項時,GetOpt 似乎不起作用,拋出異常,這個名為 o.py 的文件:import getoptimport sysopts,args = getopt.getopt(sys.argv[1:], "m:p:", ['mode', 'perf'])for opt_name,opt_value in opts: if opt_name in ('--mode'): print opt_name continue if opt_name in ('--perf'): print opt_name continue然后我在以下情況下收到運行時異常:python o.py --mode=aTraceback (most recent call last):File "o.py", line 3, in <module> opts,args = getopt.getopt(sys.argv[1:], "m:p:", ['mode', 'perf'])File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/getopt.py", line 88, in getopt opts, args = do_longs(opts, args[0][2:], longopts, args[1:])File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/getopt.py", line 159, in do_longs raise GetoptError('option --%s must not have an argument' % opt, opt)getopt.GetoptError: option --mode must not have an argumentopts, args = do_longs(opts, args[0][2:], longopts, args[1:])文件 "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/getopt.py", line 159, in do_longs raise GetoptError('option --%s must not have an argument' % opt, opt ) getopt.GetoptError: 選項 --mode 不能有參數那么我哪里出錯了,如何解決呢?
添加回答
舉報
0/150
提交
取消