option argument length

Ritesh Raj Sarraf rrs at researchut.com
Mon Dec 5 19:34:45 CET 2005

Hash: SHA1

Peter Otten on Monday December 5 2005 03:34 wrote:

> options, args = parser.parse_args(values=MyValues())
> but you should do your users a favour and give them meaningful error
> messages. I can't conceive how you could achieve this by checking the
> number of options. Explicit constraint checks like
> options, args = parser.parse_args()
> if options.eat_your_cake and options.have_it:
>     parser.error("Sorry, you cannot eat your cake and have it")
> will increase your script's usability and make it easier to maintain for
> only a tiny amount of work.

I'm using this for "option arguments" which are mutually inclusive.
But I want the user to pass atleast one "option argument" for the program to
function properly.

For example, I have an option "--fetch-update" which requires a file "foo"
to check what it has to fetch. If the file is provided as an argument, it
uses it, else I add a parser.set_defaults("foo") which makes the program to
look for it in the current working directory.

WHen the program see the "--fetch-update" option, it should execute the
required code. Now how do I check if at least one option has been passed at
the command-line ?
I have multiple options but I have parser.set_defaults() for each of them.


- -- 
Ritesh Raj Sarraf
RESEARCHUT -- http://www.researchut.com
"Stealing logics from one person is plagiarism, stealing from many is
"Necessity is the mother of invention."

Note: Please CC me. I'm not subscribed to the list
Version: GnuPG v1.4.2 (GNU/Linux)


More information about the Python-list mailing list