在argparse中,可以通过如下代码创建一个选择参数:
我该如何使其显示参数的名称,以便输出更像:
parser = argparse.ArgumentParser()
parser.add_argument("action", type=str,
help="The action to do. Eligible values:\ninstall, remove, version", choices=['install', 'remove', 'version'])
当 parser
是一个 argparse.ArgumentParser()
的实例时
然而,在显示帮助时,参数不是按照名称指定,而是指定为 {install,remove,version}
,整个输出如下:
positional arguments:
{install,remove,version}
The action to do. Eligible values: install, remove,
version
optional arguments:
-h, --help show this help message and exit
我该如何使其显示参数的名称,以便输出更像:
positional arguments:
action The action to do. Eligible values: install, remove,
version
optional arguments:
-h, --help show this help message and exit