最佳答案
假设我有以下argparse片段:
diags.cmdln_parser.add_argument( '--scan-time',
action = 'store',
nargs = '?',
type = int,
default = 5,
help = "Wait SCAN-TIME seconds between status checks.")
目前,--help
返回:
usage: connection_check.py [-h]
[--version] [--scan-time [SCAN_TIME]]
Test the reliability/uptime of a connection.
optional arguments:
-h, --help show this help message and exit
--version show program's version number and exit
--scan-time [SCAN_TIME]
Wait SCAN-TIME seconds between status checks.
我更喜欢这样的东西:
--scan-time [SCAN_TIME]
Wait SCAN-TIME seconds between status checks.
(Default = 5)
查看帮助格式化程序代码可以看到有限的选项。是否有一种聪明的方法可以让argparse
以类似的方式打印--scan-time
的默认值,或者我应该直接子类化help
格式化器?