This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author wm
Recipients wm
Date 2011-02-28.16:51:32
SpamBayes Score 1.3386663e-08
Marked as misclassified No
Message-id <1298911895.1.0.590272861033.issue11354@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2011-02-28 16:51:35wmsetrecipients: + wm
2011-02-28 16:51:35wmsetmessageid: <1298911895.1.0.590272861033.issue11354@psf.upfronthosting.co.za>
2011-02-28 16:51:33wmlinkissue11354 messages
2011-02-28 16:51:33wmcreate