paul j3 added the comment:

Oops, I was wrong about this:
"Argparse doesn't prohibit all interspersed positionals.  You could, for 
example, have one or more positionals with other nargs that could be 
interspersed.  But the REMAINDER one has to be last."

    parser.add_argument('a')
    parser.add_argument('--foo')
    parser.add_argument('rest', nargs='...')
    parser.parse_args('a --foo b c'.split(' ')

produces:

    Namespace(a='a', foo=None, rest=['--foo', 'b', 'c'])

That is because, 'rest' matches an empty list of arguments.  With an nargs='*' 
or '?', the same thing happens, both 'a' and 'rest' are used up when processing 
the first positional argument string.

nargs=argparse.PARSER (= 'A...') gives the expected

    Namespace(a='a', foo='b', rest=['c'])

In this case, 'rest' has to wait till the second set of positionals.

Documentation warns "Note that it generally doesn’t make much sense to have 
more than one positional argument with nargs='*'".  Maybe it should warn 
against combining any of the 'zero or more' positionals with other positionals.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue13966>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to