Author gray_hemp
Recipients gray_hemp
Date 2010-07-06.16:24:37
SpamBayes Score 0.000871981
Marked as misclassified No
Message-id <1278433481.81.0.201692715302.issue9182@psf.upfronthosting.co.za>
In-reply-to
Content
Hello,

I am starting to use argparse package and faced the problem where an optional argument w/ nargs='+' conflicts w/ a positional argument. 

Here is the test case:

>>> import argparse
>>> p = argparse.ArgumentParser()
>>> p.add_argument('foo', type=str)
_StoreAction(option_strings=[], dest='foo', nargs=None, const=None, default=None, type=<type 'str'>, choices=None, help=None, metavar=None)
>>> p.add_argument('-b', '--bar', type=int, nargs='+')
_StoreAction(option_strings=['-b', '--bar'], dest='bar', nargs='+', const=None, default=None, type=<type 'int'>, choices=None, help=None, metavar=None)
>>> p.print_help()
usage: [-h] [-b BAR [BAR ...]] foo

positional arguments:
  foo

optional arguments:
  -h, --help            show this help message and exit
  -b BAR [BAR ...], --bar BAR [BAR ...]
>>> p.parse_args('-b 123 456 bla'.split())
usage: [-h] [-b BAR [BAR ...]] foo
: error: argument -b/--bar: invalid int value: 'bla'


It prints this usage string "usage: [-h] [-b BAR [BAR ...]] foo" so it is assumed that I could use this " -b 123 456 bla" but it does not works. 

How could it be and how to solve it? 

Thank you in advance.
History
Date User Action Args
2010-07-06 16:24:41gray_hempsetrecipients: + gray_hemp
2010-07-06 16:24:41gray_hempsetmessageid: <1278433481.81.0.201692715302.issue9182@psf.upfronthosting.co.za>
2010-07-06 16:24:38gray_hemplinkissue9182 messages
2010-07-06 16:24:38gray_hempcreate