[issue35495] argparse does not honor default argument for nargs=argparse.REMAINDER argument
Michael Blahay
report at bugs.python.org
Fri May 10 14:19:48 EDT 2019
Michael Blahay <mblahay at gmail.com> added the comment:
For the purpose of facilitating continuing conversation, here are two tests that contrast the use of * versus REMAINDER
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('foo', nargs=1,default=['none'])
parser.add_argument('bar', nargs=argparse.REMAINDER,default=['nothing'])
parser.add_argument('baz', nargs='*', default=['nada'])
parser.parse_args('a b c'.split())
Out[7]: Namespace(bar=['b', 'c'], baz=['nada'], foo=['a'])
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('foo', nargs=1,default=['none'])
parser.add_argument('baz', nargs='*', default=['nada'])
parser.add_argument('bar', nargs=argparse.REMAINDER,default=['nothing'])
parser.parse_args('a b c'.split())
Out[8]: Namespace(bar=[], baz=['b', 'c'], foo=['a'])
You can see that * and REMAINDER do differ in functionality when they are the last defined argument.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue35495>
_______________________________________
More information about the Python-bugs-list
mailing list