Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #13090 > unrolled thread
| Started by | Robert Kern <robert.kern@gmail.com> |
|---|---|
| First post | 2011-09-10 18:44 -0500 |
| Last post | 2011-09-10 18:44 -0500 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: optionparse: how to add a line break to the help text Robert Kern <robert.kern@gmail.com> - 2011-09-10 18:44 -0500
| From | Robert Kern <robert.kern@gmail.com> |
|---|---|
| Date | 2011-09-10 18:44 -0500 |
| Subject | Re: optionparse: how to add a line break to the help text |
| Message-ID | <mailman.956.1315698254.27778.python-list@python.org> |
On 9/10/11 5:16 PM, Rafael Durán Castañeda wrote:
> On 10/09/11 22:43, Gelonida N wrote:
>> I'm having a small question about optionparse.
>>
>> Normaly optionparser will format the help text according to the
>> console's width.
>>
>> I just wondered if there is any way to insert a line breakk into an
>> options help text.
>>
>> Example:
>>
>> from optparse import OptionParser
>>
>> parser = OptionParser()
>> parser.add_option("-f", action="store",
>> help="This option is really really complicated"
>> " and I'd like to write"
>> " a few paragrpahs to explain how it works."
>> "\nHowever the line breaks are stripped off"
>> " and it's thus difficult to structure the help text")
>>
>> args = ['-h']
>> parser.parse_args(args)
>>
>> Is there any trick to force a new paragraph/ line break before the word
>> 'However'?
>>
>>
>> Thanks in advance for suggestions.
>>
>>
> You can use """ for multiple line texts:
> >>> text = \
> ... """fsdfsfsdfsdf
> ... sfsdfsfsdf
> ... sdfsdf s
> ...
> ... """
> >>> text
> 'fsdfsfsdfsdf\n sfsdfsfsdf\nsdfsdf s\n\n'
That's not the problem. OptionParser removes all of the original newlines that
are in the given text when it formats the text for display. I don't think there
is a simple workaround.
--
Robert Kern
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
Back to top | Article view | comp.lang.python
csiph-web