Suggested feature: slice syntax within tuples (or even more generally)?
steve+comp.lang.python at pearwood.info
Thu Feb 14 09:03:50 CET 2013
On Wed, 13 Feb 2013 21:54:43 -0800, stephenwlin wrote:
>> I believe the idea of slice literals has been rejected.
> That's too bad...do you have a link to prior discussion on this and what
> the reasoning was for rejection?
Is that intended as "if slice(x, None, None)" with a missing colon, or
"if x" with colon supplied?
With the addition of one extra letter, you can use slice notation to
return slice objects:
def __getitem__(self, item):
s = SlicerAndDicer()
And some examples:
slice(2, None, 5)
slice(None, None, -1)
py> s[3, 4]
py> s[3, 4:6]
(3, slice(4, 6, None))
py> s[7::, 9]
(slice(7, None, None), 9)
I feel all giddy inside...
By the way, Go-lang also has slices, but they're more like views into an
array than Python's slice objects.
This is not germane to your question, I just found it interesting reading.
More information about the Python-list