Message129714
Hi, sometimes it is needed to grab variable, but limited, number of options.
For example --point could accept 2, 3 or 4 values: (x,y) or (x,y,z) or
(x,y,z,w). Current version of argparse requires postprocessing:
parser.add_argument('--point', action='append', default=[])
nmps = parser.parse_args()
if not (2 <= len(nmsp.point) <= 4):
raise argparse.ArgumentTypeError("--point expects 2, 3 or 4 values")
I propose to allow pass range of options count to nargs, including
lower/upper bound. For example:
parser.add_argument('--point', nargs=(2,4) ) # from 2 to 4
parser.add_argument('--foo', nargs=(9, None) ) # at least 9
parser.add_argument('--bar', nargs=(None, 7) ) # at most 7
nmsp = parser.parse_args()
I've attached tests and patch made against Python3.2 lib from Debian.
w. |
|
Date |
User |
Action |
Args |
2011-02-28 16:51:35 | wm | set | recipients:
+ wm |
2011-02-28 16:51:35 | wm | set | messageid: <1298911895.1.0.590272861033.issue11354@psf.upfronthosting.co.za> |
2011-02-28 16:51:33 | wm | link | issue11354 messages |
2011-02-28 16:51:33 | wm | create | |
|