optionparse: how to add a line break to the help text

Gelonida N gelonida at gmail.com
Sun Sep 11 05:07:28 CEST 2011


Hi Tim,


Thanks a lot!!!



On 09/11/2011 04:08 AM, Tim Chase wrote:
> On 09/10/11 20:54, Gelonida N wrote:
>>> Unfortunately the help text is formatted using textwrap, which presumes
>>> that the entire text is a single paragraph.  To get paragraphs in the
>>> help text, you'll need to write an IndentedHelpFormatter subclass that
>>> splits the text on "\n\n", textwraps the split string individually, then
>>> re-joins them.  _format_text() and format_option() look like the methods
>>> that would need replacing.
> 
> Just in case you want it:
> 
> http://bytes.com/topic/python/answers/734066-how-output-newline-carriage-return-optparse
> 

It works (of course ;-) ) like a charm.
Good to know, that I'm not the only one who want's to structure the help
text a little nicer.

> 
> it's come up several times and several years ago I hacked together
> exactly the solution Rhodri mentions.

Considering, that you posted the snippet in 2007 and this is very
probably a reocurring problem for any slighty more complicated help text
it is really a pity, that it did not become of part of the standard
optparse library :-(


Thanks again.





More information about the Python-list mailing list