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


Groups > comp.lang.python > #13090

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

Path csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!feeder.news-service.com!news2.euro.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'example:': 0.03; 'args': 0.05; 'parser': 0.05; '"""': 0.07; 'removes': 0.07; 'suggestions.': 0.07; 'optparse': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'underlying': 0.09; 'width.': 0.09; 'enigma': 0.16; 'kern': 0.16; 'newlines': 0.16; 'received:austin.res.rr.com': 0.16; 'stripped': 0.16; 'wrote:': 0.16; 'advance': 0.18; '>>>': 0.18; 'insert': 0.19; 'subject:help': 0.22; 'header:In-Reply-To:1': 0.22; 'structure': 0.23; 'thus': 0.23; 'breaks': 0.23; 'wondered': 0.23; 'pm,': 0.24; "i'm": 0.27; 'import': 0.28; 'interpret': 0.29; 'thanks': 0.30; "skip:' 10": 0.30; 'break': 0.32; 'there': 0.33; 'to:addr:python- list': 0.33; '...': 0.34; 'header:User-Agent:1': 0.34; 'force': 0.34; 'header:X-Complaints-To:1': 0.35; 'subject:text': 0.35; 'problem.': 0.36; 'explain': 0.36; 'question': 0.36; 'skip:" 10': 0.36; 'formats': 0.37; 'options': 0.37; 'think': 0.38; 'received:org': 0.38; 'subject:: ': 0.39; 'received:rr.com': 0.39; 'difficult': 0.39; 'option': 0.39; 'help': 0.39; 'header:Mime- Version:1': 0.39; 'to:addr:python.org': 0.39; "i'd": 0.40; "it's": 0.40; 'according': 0.62; 'world': 0.62; 'our': 0.63; 'believe': 0.65; 'subject:line': 0.73; 'off"': 0.84; 'eco': 0.91; 'rafael': 0.91
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Robert Kern <robert.kern@gmail.com>
Subject Re: optionparse: how to add a line break to the help text
Date Sat, 10 Sep 2011 18:44:02 -0500
Organization The Church of Last Thursday
References <j4gi5r$gjc$1@dough.gmane.org> <4E6BE1CA.9030608@gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 8bit
X-Gmane-NNTP-Posting-Host cpe-70-113-40-77.austin.res.rr.com
User-Agent Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:6.0.1) Gecko/20110830 Thunderbird/6.0.1
In-Reply-To <4E6BE1CA.9030608@gmail.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.956.1315698254.27778.python-list@python.org> (permalink)
Lines 54
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1315698254 news.xs4all.nl 2436 [2001:888:2000:d::a6]:38333
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:13090

Show key headers only | View raw


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 comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: optionparse: how to add a line break to the help text Robert Kern <robert.kern@gmail.com> - 2011-09-10 18:44 -0500

csiph-web