Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/321.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/156.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 argparse位置参数的位置_Python_Argparse - Fatal编程技术网

Python argparse位置参数的位置

Python argparse位置参数的位置,python,argparse,Python,Argparse,与此相反: 用法:installer.py[-h][-v]dir 我想要这个: 用法:installer.py dir[-h][-v] 有没有一种方法可以指定位置参数的位置?如果设置位置参数,则该参数可以以任何一种方式使用,因此您仍然可以 installer.py dir[-h][-v] 和dir,这与ArgParse文档中的示例非常相似: 来自argparse文档 默认情况下,ArgumentParser根据其包含的参数计算使用情况消息: 可以使用usage=关键字参数覆盖默认消息: >>pa

与此相反:

用法:installer.py[-h][-v]dir

我想要这个:

用法:installer.py dir[-h][-v]


有没有一种方法可以指定位置参数的位置?

如果设置位置参数,则该参数可以以任何一种方式使用,因此您仍然可以

installer.py dir[-h][-v]

和dir,这与ArgParse文档中的示例非常相似:
来自argparse文档

默认情况下,ArgumentParser根据其包含的参数计算使用情况消息:

可以使用usage=关键字参数覆盖默认消息:

>>parser=argparse.ArgumentParser(prog='prog',用法='%(prog)s[options]')

usage: PROG [-h] [--foo [FOO]] bar [bar ...]
usage: PROG [options]