option argument length

Ritesh Raj Sarraf rrs at researchut.com
Mon Dec 5 13:34:45 EST 2005


-----BEGIN PGP SIGNED MESSAGE-----
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.

Regards,

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

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

iD8DBQFDlIhF4Rhi6gTxMLwRAsLTAJ9ydjppGrFVbH2kL00vL00HgtrxqQCghZBq
pC0/1HftWE+9Eipx6vF+3Bo=
=Ay8m
-----END PGP SIGNATURE-----




More information about the Python-list mailing list