470,841 Members | 1,159 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,841 developers. It's quick & easy.

Powerful Command line parsers

Is there a Command line parser in python that can:
1. resolve conflicts
2. specify something like requires
3. and smart

for ex:
python test.py --a --b --c --d

Case 1:
If 'a' is an option 'b' or 'c' cannot be specified.

Case 2:
atleast one option should be specified

Case 3:
IF 'a' and 'c' are given then 'd' has to be given

or many such cases.

I was wondering as this is a very common problem there if there is a
module that could do these things .
'optparse' is not this smart I guess.

Apr 21 '06 #1
2 1042
On 22/04/2006 4:15 AM, PyPK wrote:
Is there a Command line parser in python that can:
1. resolve conflicts
2. specify something like requires
3. and smart
"... that can ... and smart" does not compute.

for ex:
python test.py --a --b --c --d
I'm used to seeing --fubar and -f; what does --f mean?

Case 1:
If 'a' is an option 'b' or 'c' cannot be specified.

Case 2:
atleast one option should be specified

Case 3:
IF 'a' and 'c' are given then 'd' has to be given

or many such cases.

I was wondering as this is a very common problem there if there is a
module that could do these things .
'optparse' is not this smart I guess.


Modules are neither dumb nor smart. The author of optparse is IMHO
smart; it does just about what it ought to do.

To meet your specifications, the module would need to incorporate a
mini-language:

if a and (b or c): nasty("blah 1")
if not (a or b or c or d): nasty("blah 2")
if a and c and not d: nasty("blah 3")

Again IMHO, it would be an enormous waste of effort to implement such a
mini-language inside a command-line parser, when the call to the parser
can be followed by whatever conditions and actions you like, written
in Python.
Apr 21 '06 #2
In article <44**************@lexicon.net>,
John Machin <sj******@lexicon.net> wrote:
To meet your specifications, the module would need to incorporate a
mini-language:

if a and (b or c): nasty("blah 1")
if not (a or b or c or d): nasty("blah 2")
if a and c and not d: nasty("blah 3")


Prolog-style predicates. :)
Apr 22 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Will Stuyvesant | last post: by
2 posts views Thread by joe | last post: by
4 posts views Thread by Boogie El Aceitoso | last post: by
4 posts views Thread by Greg B | last post: by
reply views Thread by PyPK | last post: by
2 posts views Thread by ern | last post: by
13 posts views Thread by Chris Carlen | last post: by
reply views Thread by JosAH | last post: by
5 posts views Thread by Ramdas | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.