(no subject)
Alan Meyer <[email protected]> Thu, 5 Nov 2009 17:37:19 -0800 (PST)
| Newsgroups | gmane.comp.python.optik.user |
|---|---|
| Message-ID | <[email protected]> |
I would like to propose an easy enhancement to the description
formatting in optparse. I found ways to do what I want to do
here:
http://groups.google.com/group/comp.lang.python/browse_frm/thread/e72deee779d9989b/
but the approach looks complex and a little fragile.
The enhancement I'm proposing is to allow a programmer to specify
an OptionParser.description that is already formatted, i.e., that
will be displayed without passing it through textwrap.fill(),
which is what now happens.
The particular use case that prompted me to request this
enhancement is that I wanted to document the fixed arguments,
each on a separate line, for example:
...
parser = optparse.OptionParser(
usage = "%prog {options} fratzer coord",
description = """
This program fibrillates the umptifratz using specialized fratzer
and coordinate settings passed on the command line.
args:
fratzer = One of the three system fratzers:
"tan" - take the tangent to the fratzline
"sin" - use the sine of the fratzline
"cos" - use the cosine of the fratzline
coord = Coordinate system to use, one of:
"rectilinear"
"polar"
""")
...
I solved the problem in my program by stuffing the preformatted
text into the usage message (which is not passed through
textwrap.fill), but would like to be able to put it in the
description instead so that it's closer to where the option
documentation is displayed and only appears when fuller help is
requested.
One way to get what I want is to do what the poster to
comp.lang.python did and override the help formatter. However, a
much simpler way to enable someone to get what he wants is just
to provide an option for turning off formatting altogether and
allowing a user to provide preformatted text. For example, we
might add a new attribute to the OptionParser such as
"reformat_description", with a default value of True. Then check
the value later:
def format_description(self, formatter):
if self.parser.reformat_description:
return formatter.format_description(self.get_description())
else:
return self.get_description()
That could be added to the source for optparse in minutes,
provides total flexibility while maintaining complete backward
compatibility, and offers a trivially easy path for the
programmer to getting a formatted description.
Thank you for producing such a powerful and useful module.
--
Alan Meyer
[email protected]
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july