Another newbie getopt thread. ^_^
mynews44 at yahoo.com
Sun Jul 18 09:53:16 CEST 2004
Chris Cioffi <evenprimes at gmail.com> wrote in message news:<mailman.529.1090102630.5135.python-list at python.org>...
> On 17 Jul 2004 15:06:25 -0700, googleboy <mynews44 at yahoo.com> wrote:
> > Hiya!
> > I discovered getopt tonight after getting halfway through writing huge
> > amounts of looping statements to try to ensure that text entered as
> > parameters to my python app are within the bounds of what is allowed.
> Look at the optparse module.
> It allows you to define the parameter type, making it far easier to do
> any followup validation. As a bonues, it provides automatic support
> for stuff like 'program --help'.
Thanks for the tip. I am using 2.2 here, but a bit of research
pointed me off to optik.sourceforge.net and it is all beginning to
really come together now.
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
The docs and examples don't make it clear how to do this, and when I
defined a -h, --help option it gave me a conflict error:
optik.errors.OptionConflictError: option -h/--help: conflicting option
string(s): -h, --help
Is there anyway around this?
Finally, a quick one... Is there a way for optparse to force an
integer to be between 0 and 100? I am passing in percentage
values.... It isn't hard to make a validation on the integers
afterwards, but I thought it might be nice to have this as part of
Thanks for the help!
More information about the Python-list