I'm trying to figure out a way to have argparse positional arguments be mutually exclusive to an optional argument.
For example:
./adder 20 32
Output: 52
./adder --interactive
adder>
Right now, if I were to just try '--interactive', it tells me that I'm missing positional arguments.
Example code:
parser = argparse.ArgumentParser()
parser.add_argument('a', metavar='First')
parser.add_argument('b', metavar='Second')
parser.add_argument('--interactive')
parser.parse_args()
I was wondering if there is an elegant way to do this (preferably using argparse functionality) so that '--interactive' disables the requirement of using the two positional arguments.
add_argument('parms', nargs='*')? arguments are gathered into a list, if positional argument absent, list is empty. - georgexsh