2 回答

TA贡献1860条经验 获得超8个赞
metavar参数 toadd_argument是您正在寻找的:
parser = argparse.ArgumentParser()
parser.add_argument(
"action",
type=str,
help="The action to do. Eligible values:\ninstall, remove, version",
choices=['install', 'remove', 'version'],
metavar="action",
)
调用parser.print_help()收益率:
usage: [-h] action
positional arguments:
action The action to do. Eligible values: install, remove, version
optional arguments:
-h, --help show this help message and exit

TA贡献1805条经验 获得超10个赞
您可以指定元变量
当 ArgumentParser 生成帮助消息时,它需要某种方式来引用每个预期的参数。默认情况下,[...] 可以使用 metavar 指定替代名称:
parser = argparse.ArgumentParser()
parser.add_argument("action", type=str, metavar='action',
help="The action to do. Eligible values:\ninstall, remove, version", choices=['install', 'remove', 'version'])
添加回答
举报