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'])
添加回答
舉報