Message187178
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. |
|
Date |
User |
Action |
Args |
2013-04-17 16:34:46 | paul.j3 | set | recipients:
+ paul.j3, bethard, chris.jerdonek |
2013-04-17 16:34:46 | paul.j3 | set | messageid: <1366216486.87.0.497087817208.issue17050@psf.upfronthosting.co.za> |
2013-04-17 16:34:46 | paul.j3 | link | issue17050 messages |
2013-04-17 16:34:46 | paul.j3 | create | |
|