Author mblahay
Recipients bethard, mblahay, paul.j3, rgov
Date 2019-05-10.18:19:48
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1557512388.2.0.377419954448.issue35495@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2019-05-10 18:19:48mblahaysetrecipients: + mblahay, bethard, paul.j3, rgov
2019-05-10 18:19:48mblahaysetmessageid: <1557512388.2.0.377419954448.issue35495@roundup.psfhosted.org>
2019-05-10 18:19:48mblahaylinkissue35495 messages
2019-05-10 18:19:48mblahaycreate