Why doesn't the argparse argument 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 you pass the panel argument first, it works:
bar --foo 1 2 3
Now this in itself is not so bad. I can live with the presence of positional arguments in the first place, that this behavior is incompatible with the argparse help created for us, which claims that the bar should be the last:
usage: argparsetest.py [-h] [--foo FOO [FOO ...]] bar
So how do you do this work with consistent help text?
Here is the complete test program .
source share