Re: feature request #1055954: respect newlines in description
Greg Ward <[email protected]> Wed, 09 Mar 2005 19:49:39 -0500
| Newsgroups | gmane.comp.python.optik.user |
|---|---|
| Message-ID | <[email protected]> |
On 09 March 2005, Tomi Mickelsson said:
> In short, I would like to control the linefeeds in the description field.
> I do not like the way everything in the description is jammed into a
> single paragraph.
[...]
> To achieve this formatting, I have the following kludge in my code:
> ---
> import new
>
> ....code omitted
>
> # use my own description formatter method
> parser.format_description = new.instancemethod(lambda self,x :
> self.description, parser, parser.__class__)
Blecchhh. Just because you *can* rudely interfere in another class's
business does not mean that you should! Why not just subclass
OptionParser?
class MyOptionParser(OptionParser):
def format_description(self, formatter):
return self.get_description()
(You might need to add a leading or trailing newline to make it look
"just right".) So your kludge is not a compelling argument for this
feature. Anyone who wants their descriptions formatted "just so" can
just override format_description() as shown. (Or provide a custom
HelpFormatter and do it there.)
A compelling argument would be if someone wanted multiple paragraphs in
the description. My proposed interface for that would be
parser = OptionParser(...,
description=[paragraph1,
paragraph2,
...,
paragraphN],
...)
Passing a string X would be equivalent to passing the list [X]. Each
paragraph would be wrapped individually, and then they would be printed
*with a blank line between them*.
That's easy to implement, easy to explain, and easy to use. Magic
tricks to split a single string into paragraphs are a non-starter for
me. (Which is why textwrap.py resolutely refuses to consider its input
string as anything other than a single paragraph. There was talk at one
point about adding a split-into-paragraphs function to textwrap.py, but
I guess it never happened.)
So: does anyone want this feature? If so, I'll hijack Tomi's SF item
and implement it. If not -- never mind.
Greg
--
Greg Ward <[email protected]> http://www.gerg.ca/
Yield to temptation; it may not pass your way again.
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click