paul j3 added the comment:
The problem isn't with REMAINDER, but with the distinction between optionals
and arguments. If you change '--def' to 'def', the parse should work:
>>> p = ArgumentParser(prog='test.py')
>>> p.add_argument('remainder', nargs=argparse.REMAINDER)
>>> p.parse_args(['def'])
'--def' would give problems with almost all of the nargs options, especially
'*' and '?'.
The issue is that '--def' looks like an optional. Since it is not found in the
defined arguments, it is classed as an unknown extra and skipped (try
p.parse_known_args(['--def'])). All of this takes place before 'REMAINDER' has
a chance to look at the argument strings.
In http://bugs.python.org/issue9334 I submitted a patch that defines a
'args_default_to_positional' parser option. If this is True, that unrecognized
'--def' would be classed as a 'positional' and would be captured by the
REMAINDER.
----------
nosy: +paul.j3
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue17050>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com