命令行参数的传递方式是否有标准,或者程序之间是否有所不同?例如,这里有几个例子:$ script.py -a 2$ script.py -a=2$ script.py a=2$ script.py --all 2$ script.py --all=2
1 回答
![?](http://img1.sycdn.imooc.com/533e4c9c0001975102200220-100-100.jpg)
千万里不及你
TA贡献1784条经验 获得超9个赞
如果您使用argparse,您将发现对上述大多数选项的支持。例如:
# test.py
import argparse
parser = argparse.ArgumentParser(description='Dedupe library.')
parser.add_argument( '-a', '--all', nargs='+', type = int, help='(Optional) Enter one or more Master IDs.')
跑步:
df$ python test.py -a 2
# {'all': [2]}
df$ python test.py -a=2
# {'all': [2]}
df$ python test.py a=2
# test.py: error: unrecognized arguments: a=2
$ python test.py --all 2
# {'all': [2]}
$ python test.py --all=2
# {'all': [2]}
如您所见,除了以下形式之外,所有内容均受支持script.py a=2
添加回答
举报
0/150
提交
取消