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

Tim Chase python.list at tim.thechases.com
Sun Sep 11 13:05:56 CEST 2011


On 09/10/11 22:07, Gelonida N wrote:
>> 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.
>
> 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 :-(

Even at the time, the optparse library wasn't readily patchable 
as the inline documentation gave some dire warning about "don't 
edit this directly, as this file is generated from some other 
source"—I never was able to dig up that source to patch against.

As Ben Finney replied, optparse is now deprecated, replaced in 
part by argparse. Unfortunately, argparse wasn't backported to 
the standard library for earlier 2.x series (I think it became 
available in 2.7, and may run in earlier versions if manually 
added like I had to do on my Debian Py2.6 install). But that 
makes it hard for those of us who want to use a built-in 
option-parsing library across a wide variety of Python versions. 
  I don't strongly care which I use except that I want it to be 
broadly available with minimal fuss.

-tkc





More information about the Python-list mailing list