Skip to content
Advertisement

Python argparse conditional requirements

How do I set up argparse as follows:

JavaScript

For example,

JavaScript

There are a number of similar questions here, but either they don’t address this situation or I don’t understand.

Python 2.7 if that matters.

Advertisement

Answer

A subparser (as suggested in comments) might work.

Another alternative (since mutually_exclusive_group can’t quite do this) is just to code it manually, as it were:

JavaScript

Adding a little driver to this:

JavaScript

and run with your examples, it seems to do the right thing; here are two runs:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement