Message186000
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. |
|
Date |
User |
Action |
Args |
2013-04-04 03:26:25 | paul.j3 | set | recipients:
+ paul.j3, bethard, kalt, Laszlo.Attila.Toth |
2013-04-04 03:26:25 | paul.j3 | set | messageid: <1365045985.1.0.0908498798519.issue13966@psf.upfronthosting.co.za> |
2013-04-04 03:26:25 | paul.j3 | link | issue13966 messages |
2013-04-04 03:26:24 | paul.j3 | create | |
|