command line arguments

Michael Hoffman cam.ac.uk at mh391.invalid
Wed Aug 31 16:05:56 EDT 2005


wittempj at hotmail.com wrote:

> py>    parser.add_option("-n", "--name", dest="name", action="store",
> py>   			help="enter a name")
 > py>    parser.add_option("-u", "--url", action="store", dest="url",
 > help = "enter an url")

It's worth noting that this will have the same effect and involves less 
repetitive typing:

parser.add_option("-n", "--name", help="enter a name")
parser.add_option("-u", "--url", help="enter a url")

Discovering this has made optparse usage much more painless for me, and 
also reduces the incidence of those nasty multiple line option additions.

Although I should note for the record that I agree with Peter Hansen 
that if the arguments are not *optional* then they should not be made 
options in this manner.
-- 
Michael Hoffman



More information about the Python-list mailing list