Message276503
Clint, 'nargs=argparser.REMAINDER' ('...') may do what you want
p=argparse.ArgumentParser()
p.add_argument('--subscipt_args', nargs='...')
p.add_argument('pos',nargs='*')
p.parse_args('--subscipt_args --foo --bar --baz -- other args'.split())
produces
Namespace(pos=['other', 'args'], subscipt_args=['--foo', '--bar', '--baz'])
'REMAINDER' is like '*' except it takes everything. But the '--' means 'everything that follows is a positional argument, so it effectively ends the 'REMAINDER'. 'REMAINDER' is documented (briefly), but I don't recall reading about its interaction with '--'. I'm a little surprised that it wasn't mentioned earlier in this bug/issue.
'+...', argparse.PARSER is similar except it requires at least one argument. It is used by the 'subparsers' argument, to collect the cmd string and use all that follow as subparser arguments.
There is a bug issue (or two) about what should happen when there are more than one '--' argument. |
|
Date |
User |
Action |
Args |
2016-09-15 02:30:30 | paul.j3 | set | recipients:
+ paul.j3, cben, amcnabb, bethard, eric.smith, eric.araujo, r.david.murray, memeplex, gfxmonk, andersk, abacabadabacaba, gdb, nelhage, drm, davidben, martin.panter, skilletaudio, Christophe.Guillon, danielsh, spaceone, Clint Olsen |
2016-09-15 02:30:30 | paul.j3 | set | messageid: <1473906630.8.0.508712730998.issue9334@psf.upfronthosting.co.za> |
2016-09-15 02:30:30 | paul.j3 | link | issue9334 messages |
2016-09-15 02:30:30 | paul.j3 | create | |
|