PEP proposal optparse

Steven D'Aprano steve at
Thu Sep 18 15:11:07 CEST 2008

On Thu, 18 Sep 2008 03:37:54 -0700, James wrote:

> Hi,
> I would like to know your thoughts on a proposed change to optparse that
> I have planned. It is possible to add default values to multiple options
> using the set_defaults. However, when adding descriptions to options the
> developer has to specify it in each add_option() call. This results in
> unreadable code such as:

I don't find it unreadable at all. I find it very helpful to have the 
help text associated right there with the rest of the option, instead of 
hidden in a different function call.

> Help descriptions can often be quite long and separating them in this
> fashion would, IMHO, be desirable.

If the help descriptions are so long that they are a problem, then the 
solution I would choose is to put them in their own module, then do 
something like this:

import docs
parser.add_option('-q', '--quiet', action="store_false",
    dest='verbose', help=docs.quiet)
parser.add_option('-o', '--output', type='string',
    dest='castordir', metavar='<DIR>', help=docs.output)



More information about the Python-list mailing list