What method does slice notation call?
Robert Brewer
fumanchu at amor.org
Thu Oct 9 02:37:13 EDT 2003
>>> class A(types.DictType):
... def __getitem__(self, key):
... return types.DictType.__getitem__(self, key)
...
>>> a = A()
>>> a[0] = 3
>>> a.__getitem__ = lambda x: "w00t"
>>> a.__getitem__(0)
'w00t'
>>> a
{0: 3}
>>> a[0]
3
Can anyone tell me why a[0] doesn't return "w00t", like I thought it
would? What method is a[0] calling? Is there a way to override it?
Robert Brewer
MIS
Amor Ministries
fumanchu at amor.org
More information about the Python-list
mailing list