[issue14191] argparse: nargs='*' doesn't parse all positional parameters

Glenn Linderman report at bugs.python.org
Sun Mar 4 07:37:33 CET 2012


New submission from Glenn Linderman <v+python at g.nevcal.com>:

To me, "all positional parameters" mean whether they are in the front, back or middle, as long as they are not diriectly preceded by an option that can accept an unlimited number of parameters.

from argparse import ArgumentParser, SUPPRESS, REMAINDER
import sys
print( sys.version )
parser = ArgumentParser()
parser.add_argument('--foo', dest='foo')
parser.add_argument('--bar', dest='bar')
parser.add_argument('baz', nargs='*')
print( parser.parse_args('a b --foo x --bar 1 c d'.split()))
# expected:  Namespace(bar='1', baz=['a', 'b', 'c', 'd'], foo='x')
# actual: error: unrecognized arguments: c d

Above also supplied as a test file, t12.py

----------
components: Library (Lib)
files: t12.py
messages: 154880
nosy: v+python
priority: normal
severity: normal
status: open
title: argparse: nargs='*' doesn't parse all positional parameters
type: behavior
versions: Python 3.2
Added file: http://bugs.python.org/file24726/t12.py

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


More information about the Python-bugs-list mailing list