选项参数的标准 cmd 行分隔
Standard cmd line separation for option-arguments
是否有关于如何传递命令行参数的标准,或者这是否因程序而异?例如,这里有几个例子:
$ script.py -a 2
$ script.py -a=2
$ script.py a=2
$ script.py --all 2
$ script.py --all=2
如果您使用 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
的形式外,其他都支持
是否有关于如何传递命令行参数的标准,或者这是否因程序而异?例如,这里有几个例子:
$ script.py -a 2
$ script.py -a=2
$ script.py a=2
$ script.py --all 2
$ script.py --all=2
如果您使用 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