Suggested feature: slice syntax within tuples (or even more generally)?

Nobody nobody at nowhere.com
Tue Feb 26 08:38:19 CET 2013


On Wed, 13 Feb 2013 11:00:15 -0800, stephenwlin wrote:

> Would it be feasible to modify the Python grammar to allow ':' to generate
> slice objects everywhere rather than just indexers and top-level tuples of
> indexers?

If you need to be able to easily construct indexing objects, create a
helper like:

	> class Slicer(object):
	=     def __getitem__(self, s):
	=         return s
	= 
	> s_ = Slicer()
	> s_[1,2,3]
	(1, 2, 3)
	> s_[:]
	slice(None, None, None)
	> s_[1:2:3,4:5:6]
	(slice(1, 2, 3), slice(4, 5, 6))
	> s_[...]
	Ellipsis




More information about the Python-list mailing list