Optparse and help formatting?

Ben Finney bignose+hates-spam at benfinney.id.au
Sun Sep 30 06:15:09 CEST 2007

Tim Chase <python.list at tim.thechases.com> writes:

> I've been learning the ropes of the optparse module and have been
> having some trouble getting the help to format the way I want.

A quick perusal of the 'optparse.py' code shows me this:

class OptionParser([...]):
    def __init__([...],
        if formatter is None:
            formatter = IndentedHelpFormatter()

So, the OptionParser init method accepts the help formatter as the
'formatter' argument, defaulting to a new instance of

Presumably, it's a matter of subclassing 'optparse.HelpFormatter' and
overriding the behaviour you want to change, then passing an instance
of your new class as the 'formatter' argument to the 'OptionParser()'

 \        "Members of the general public commonly find copyright rules |
  `\     implausible, and simply disbelieve them."  -- Jessica Litman, |
_o__)                                              _Digital Copyright_ |
Ben Finney

More information about the Python-list mailing list