Why won’t argparse parse these arguments?
--foo 1 2 3 bar
Using
parser = argparse.ArgumentParser()
parser.add_argument('--foo', nargs='+')
parser.add_argument('bar')
which gives the following error:
error: too few arguments
If I pass the bar argument first though, it works:
bar --foo 1 2 3
Now, this in itself is not too bad. I can live with having the positional arguments first it’s just that this behaviour is inconsistent with the help argparse creates for us, which states that bar should be last:
usage: argparsetest.py [-h] [–foo FOO
[FOO …]] bar
So how do you make this work with consistent help text?
Here’s a complete test program.
Maybe try doing –input –output flags and setting those options to required=True in the add_argument?
http://docs.python.org/dev/library/argparse.html#the-add-argument-method