现在我的脚本通过以下方式调用:
python resylter.py -n *newfile* -o *oldfile*
代码如下:
parser.add_argument('-n', '--newfile', help='Uses only with -o argument. Compares inputed OLD (-o) file with previous run results with NEW(-n) output.xml file with actual run results')
parser.add_argument('-o', '--oldfile', help='Uses only with -n argument. Compares inputed OLD (-o) file with previous run results with NEW(-n) output.xml file with actual run results')
以及一些动作
我如何编辑它以像这样使用?:
python resylter.py -n *newfile* *oldfile*
sys.argv[-1] 不起作用
Use nargs=2
:
parser.add_argument(
'-c',
'--compare',
nargs=2,
metavar=('newfile', 'oldfile'),
help='Compares previous run results in oldfile with current run results in newfile.',
)
args = parser.parse_args()
newfile, oldfile = args.compare
还添加metavar=('newfile', 'oldfile')
如果您运行,则改进帮助文本resylter.py -h
.
Docs: nargs https://docs.python.org/3/library/argparse.html#nargs, metavar https://docs.python.org/3/library/argparse.html#metavar
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)