[issue16878] argparse: positional args with nargs='*' defaults to []

R. David Murray report at bugs.python.org
Mon Jan 7 01:51:54 CET 2013


R. David Murray added the comment:

>>> p.add_argument('-a', action="append", default=None)
>>> p.parse_args([])
Namespace(a=None)
>>> p.parse_args(['-a', '1', '-a', '2'])
Namespace(a=['1', '2'])

So there's a logical correspondence there (repeated option vs multiple values, each producing a list).

I'm not sure what you mean by the difference between options and positionals.  I note that you can use nargs with an optional, and in that case the default works, which is even more unfortunate than the difference with 'append'.  But if you can articulate a logical difference between optionals and positional here, maybe we can make it look reasonable :)

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue16878>
_______________________________________


More information about the Python-bugs-list mailing list