【发布时间】:2013-02-07 12:10:57
【问题描述】:
我正在使用 optparse 处理命令行参数,但我遇到了 optparse 帮助消息的多个空格行的问题。
group.add_option(
'-H',
'--hostname',
action='store',
dest='hostname',
help='Specify the hostname or service/hostname you want to connect to\
If specified -f/--hostfile will be ignored',
metavar='HOSTNAME',)
所以我在帮助消息中的“to”之后得到了几个空格(因为缩进)。
Specify the hostname or service/hostname you want to connect
to If specified -f/--hostfile will be ignored
我可以删除帮助消息第二行中的前导空格,但那将是不符合 Python 的。
是否有一些pythonic方法可以删除帮助消息中的空格。
【问题讨论】:
-
注意:自 python 2.7 版起,不鼓励使用 optparse。 optparse 模块已弃用,不会进一步开发; argparse 模块将继续开发。请参阅PEP 0389 了解更多信息。
标签: python arguments command-line-arguments optparse