Internal processing of extended slicing
June Kim
junaftnoon at nospamplzyahoo.com
Mon Jan 1 09:38:34 EST 2001
Some observations on extended slice syntax gave me a clue:
class eslice:
def __getitem__(self,arg)
print arg
>>> a=eslice()
>>> a[0:1:10]
slice(0,1,10)
>>> a[0:1:20,10:15, ...]
(slice(0, 1, 20), slice(10, 15, None), Ellipsis)
And as the Python Reference Manual goes, "The primary must evaluate to a
mapping object, and it is indexed with a key that is constructed from the
slice list, ..., the conversion of the lone slice item is the key. ... The
conversion of a proper slice is a slice object..."
So I supposed,
>>> slidic={slice(0,2,1):100}
>>> slidic[0:2:1]
would give me 100, but instead it spits out:
Traceback (most recent call last):
File "<stdin>", line 1, in ?
KeyError: slice(0, 2, 1)
The problem seems to be the fact that:
>>> slice(0,2,1) == slice(0,2,1)
0
What is the internal process of e-slice syntax with dictionaries and how can
I get access to 100 in the dictionary?
ps. I have no problem using e-slice with NumPy arrays but wants to know the
internals.
More information about the Python-list
mailing list