Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getopt - won't allow an option to have param, or NOT have param

Status
Not open for further replies.

hmerrill

Programmer
Dec 4, 2000
473
US
I'm a python newbie, and I'm trying to use "getopt" to process command line arguments. I'd like to be able to specify a command line option that *could* have an associated argument, but getopt is forcing me to declare each option to be

*either*
1. with an associated argument

*or*
2. without an associated argument

and there doesn't seem to be any in-between. Is there a way to use getopt in such a way as to allow me to specify an option to *either* have an associated argument, or not? For example, if I have option "--abc", then I want to be able to specify "--abc" either with an argument(--abc="def"), or without an argument(--abc), and have both be legal in terms of getopt. Is this possible?

TIA. Hardy Merrill
 
Well, I am not an expert on getopt, but I did go in and peruse the source code, and I *think* it isn't possible to have a switch where the argument is optional. Sorry... that's the best I could do.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top