使用python的optparse模块我想在常规用法输出下添加额外的示例行。我现在help_print()输出如下:python optparse,如何在使用输出中包含附加信息?
usage: check_dell.py [options]
options:
-h, --help show this help message and exit
-s, --storage checks virtual and physical disks
-c, --chassis checks specified chassis components
我想这是包括我的工作不太* nix的识字用户使用的例子。像这样的:
usage: check_dell.py [options]
options:
-h, --help show this help message and exit
-s, --storage checks virtual and physical disks
-c, --chassis checks specified chassis components
Examples:
check_dell -c all
check_dell -c fans memory voltage
check_dell -s
我该如何做到这一点?什么optparse选项允许这样?当前代码:
import optparse
def main():
parser = optparse.OptionParser()
parser.add_option('-s', '--storage', action='store_true', default=False, help='checks virtual and physical disks')
parser.add_option('-c', '--chassis', action='store_true', default=False, help='checks specified chassis components')
(opts, args) = parser.parse_args()
迁移到argparse :-) – 2017-01-12 11:12:22