>>> import argparse
>>> p = argparse.ArgumentParser(prog='PROG')
>>> p.add_argument('bar', nargs='?')
>>> p.add_argument('foo', nargs='?')
>>> p.parse_args([]) # zero
Namespace(bar=None, foo=None)
>>> p.parse_args(['1']) # one
Namespace(bar='1', foo=None)
>>> p.parse_args(['1', '2']) # two
Namespace(bar='1', foo='2')
>>> p.print_usage()
usage: PROG [-h] [bar] [foo]
Sure, but that wasn't the question. The ordering of foo and bar in my
case is important (and btw, it is equivalent to "command [bar
[foo]]").
No, there's currently no way of getting this behavior. Your best bet
is probably to specify nargs='?' twice, and then do some post-hoc
processing to decide which is which, e.g.:
if args.bar is None:
args.bar = args.foo
args.foo = None
Steve
--
Where did you get that preposterous hypothesis?
Did Steve tell you that?
--- The Hiphopopotamus