This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author paul.j3
Recipients Laszlo.Attila.Toth, bethard, kalt, paul.j3
Date 2013-04-04.03:26:24
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1365045985.1.0.0908498798519.issue13966@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2013-04-04 03:26:25paul.j3setrecipients: + paul.j3, bethard, kalt, Laszlo.Attila.Toth
2013-04-04 03:26:25paul.j3setmessageid: <1365045985.1.0.0908498798519.issue13966@psf.upfronthosting.co.za>
2013-04-04 03:26:25paul.j3linkissue13966 messages
2013-04-04 03:26:24paul.j3create