我正在使用optparse來處理命令行參數,並且我正在運行optparse幫助消息的多個空行的問題。Python 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',)
所以我「到」在幫助信息(因爲壓痕)後得到一對夫婦在幫助信息的空間。
Specify the hostname or service/hostname you want to connect
to If specified -f/--hostfile will be ignored
我可以刪除幫助消息的第二行中的主要空格,但這將是unpythonic。
是否有一些pythonic方法來刪除幫助消息中的空格。
**注意**:自從python版本2.7以後,不鼓勵使用* optparse *。 optparse模塊已棄用,不會進一步開發;開發將繼續使用* argparse *模塊。有關更多信息,請參見[PEP 0389](http://www.python.org/dev/peps/pep-0389/)。 – shakaran 2013-04-03 23:32:59