Another newbie getopt thread. ^_^

Christopher T King squirrel at WPI.EDU
Mon Jul 19 15:03:14 CEST 2004

On 18 Jul 2004, googleboy wrote:

> There is one smallish issue I am having with getopt just at the
> moment,  and that is with this bonus feature of automatic support for
> -h, --help.  I have defined a whole bunch of things (like bugs,  my
> email address, a preamble explaining the app's function) which I want
> to print to the screen when someone requests help,  not just an
> obvious usuge and options definition.  I think it is probably
> fortunate that I have done it as 5 smaller strings instead of one huge
> one, just in case there was a time when I wanted to use only a
> subsection (like when someone puts in a bad value,  I will print a
> small error referring to the incorrect option, and the syntax example
> only.)

Using % substitution should work for this:

help = '%s %s %s\n%s\n%s' % (appname,version,build,author,usage)

or, if these things are defined in a dictionary:

help = '%(appname)s %(version)s %(build)s\n%(author)s\n%(usage)s' % helpinfo

More information about the Python-list mailing list