在 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()
但是,在显示帮助时,不是将 arg 指定为其名称,而是将其指定为{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
我怎样才能让他显示 arg 的名称,所以输出更像
positional arguments:
action The action to do. Eligible values: install, remove,
version
optional arguments:
-h, --help show this help message and exit
桃花长相依
holdtom
相关分类