I need to get to work something like this:
./foo.py [-b option [-a]]
with argparse. I thought about using sub_parsers, but I don’t know how to make it work.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The straightforward way is to simply add rules in the codes that gets your options to throw an error if -a is there and not b (and document it in the user help). You can also override the usage string using the
usagekeyword: http://docs.python.org/dev/library/argparse.html#usagesub_parsers are nice, but I don’t think they fit your needs. Their usecase is more like putting a lot of features in a single executable (think svn add, svn ci, svn co, etc)