Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #13086

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

Date 2011-09-11 00:16 +0200
From Rafael Durán Castañeda <rafadurancastaneda@gmail.com>
Subject Re: optionparse: how to add a line break to the help text
References <j4gi5r$gjc$1@dough.gmane.org>
Newsgroups comp.lang.python
Message-ID <mailman.952.1315693006.27778.python-list@python.org> (permalink)

Show all headers | View raw


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'

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Re: optionparse: how to add a line break to the help text Rafael Durán Castañeda <rafadurancastaneda@gmail.com> - 2011-09-11 00:16 +0200
  Re: optionparse: how to add a line break to the help text "Rhodri James" <rhodri@wildebst.demon.co.uk> - 2011-09-11 02:12 +0100
    Re: optionparse: how to add a line break to the help text Gelonida N <gelonida@gmail.com> - 2011-09-11 03:54 +0200
    Re: optionparse: how to add a line break to the help text Tim Chase <python.list@tim.thechases.com> - 2011-09-10 21:08 -0500
    Re: optionparse: how to add a line break to the help text Gelonida N <gelonida@gmail.com> - 2011-09-11 05:07 +0200
      Re: optionparse: how to add a line break to the help text Ben Finney <ben+python@benfinney.id.au> - 2011-09-11 15:20 +1000
        Re: optionparse: how to add a line break to the help text Gelonida N <gelonida@gmail.com> - 2011-09-11 16:30 +0200
    Re: optionparse: how to add a line break to the help text Tim Chase <python.list@tim.thechases.com> - 2011-09-11 06:05 -0500
    Re: optionparse: how to add a line break to the help text Robert Kern <robert.kern@gmail.com> - 2011-09-11 15:22 -0500

csiph-web