Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何修复opt parse optpasse.OptionError:无效的长选项字符串'-已提交。cl';:必须以--开头,后跟非破折号_Python_Optparse - Fatal编程技术网

Python 如何修复opt parse optpasse.OptionError:无效的长选项字符串'-已提交。cl';:必须以--开头,后跟非破折号

Python 如何修复opt parse optpasse.OptionError:无效的长选项字符串'-已提交。cl';:必须以--开头,后跟非破折号,python,optparse,Python,Optparse,我使用OptionParser有以下选项 parser = OptionParser() parser.add_option("-submitted.cl", "--change_list", dest="change_list",help="Submitted Change list") parser.add_option("-submitted.cr", "--crlist", dest="cr_list",help="Submitted CR list") parser.add_optio

我使用OptionParser有以下选项

parser = OptionParser()
parser.add_option("-submitted.cl", "--change_list", dest="change_list",help="Submitted Change list")
parser.add_option("-submitted.cr", "--crlist", dest="cr_list",help="Submitted CR list")
parser.add_option("-build.location", "--sbl", dest="sbl",help="Source build location")
parser.add_option("-filer.location", "--dbl", dest="dbl",help="Filer location")
parser.add_option("-users", "--users",dest="users",help="Users")
(options, args) = parser.parse_args()
我正在使用以下选项运行脚本,并遇到以下错误,请提供有关如何修复它的输入

python save_build_artifacts.py 12345 02384 \\ben\cnss_dev_integration\nfc_builds\LA_host_builds\8084\Build2  \\ben\cnss_dev_integration\temp gnakkala
错误:-

Traceback (most recent call last):
  File "save_build_artifacts.py", line 75, in <module>
    main()
  File "save_build_artifacts.py", line 43, in main
    parser.add_option("-submitted.cl", "--change_list", dest="change_list",help="Submitted Change list")
  File "C:\Python27\lib\optparse.py", line 1012, in add_option
    option = self.option_class(*args, **kwargs)
  File "C:\Python27\lib\optparse.py", line 566, in __init__
    self._set_opt_strings(opts)
  File "C:\Python27\lib\optparse.py", line 606, in _set_opt_strings
    self)
optparse.OptionError: invalid long option string '-submitted.cl': must start with --, followed by non-dash
回溯(最近一次呼叫最后一次):
文件“save_build_artifacts.py”,第75行,在
main()
文件“save_build_artifacts.py”,第43行,在main中
parser.add_选项(“-submitted.cl”,“--change_list”,dest=“change_list”,help=“submitted change list”)
文件“C:\Python27\lib\optparse.py”,第1012行,在add\u选项中
option=self.option\u类(*args,**kwargs)
文件“C:\Python27\lib\optparse.py”,第566行,在_init中__
self.\u set\u opt\u字符串(opts)
文件“C:\Python27\lib\optpasse.py”,第606行,在\u set\u opt\u字符串中
(自我)
optparse.OptionError:无效的长选项字符串“-submitted.cl”:必须以--开头,后跟非破折号

解析器中的第一个参数。add_选项用于短参数<代码>-submitted.cl太长,因为短参数只有一个字符长。所以试试类似的方法

from optparse import OptionParser

parser = OptionParser()
parser.add_option("-c", "--change_list", dest="change_list",help="Submitted Change list")
parser.add_option("-r", "--crlist", dest="cr_list",help="Submitted CR list")
parser.add_option("-b", "--sbl", dest="sbl",help="Source build location")
parser.add_option("-f", "--dbl", dest="dbl",help="Filer location")
parser.add_option("-u", "--users",dest="users",help="Users")
(options, args) = parser.parse_args()
在调用过程中,还需要命名正在使用的参数,如
python save\u build\u artifacts.py 23 43-c file.xy

请看下面的示例


(并考虑使用AgPARSE代替。Optparse被弃用)< /P>什么是Python版本,optPARSE已经在Python 2.7中被弃用。尝试使用argparse。