假设我有以下argparse片段:
diags.cmdln_parser.add_argument( '--scan-time',
action = 'store',
nargs = '?',
type = int,
default = 5,
help = "Wait SCAN-TIME seconds between status checks.")
Run Code Online (Sandbox Code Playgroud)
目前,--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.
Run Code Online (Sandbox Code Playgroud)
我更喜欢这样的东西:
--scan-time [SCAN_TIME]
Wait SCAN-TIME seconds between status checks.
(Default = 5)
Run Code Online (Sandbox Code Playgroud)
偷看帮助格式化程序代码显示有限的选项.是否有一种聪明的方式来argparse以--scan-time类似的方式打印默认值,或者我应该只是 …