Message109402
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. |
|
Date |
User |
Action |
Args |
2010-07-06 16:24:41 | gray_hemp | set | recipients:
+ gray_hemp |
2010-07-06 16:24:41 | gray_hemp | set | messageid: <1278433481.81.0.201692715302.issue9182@psf.upfronthosting.co.za> |
2010-07-06 16:24:38 | gray_hemp | link | issue9182 messages |
2010-07-06 16:24:38 | gray_hemp | create | |
|