Message13987
class tuple2(tuple):
· def __getitem__(self, index):
· · return 2*tuple.__getitem__(self, index)
class str2(str):
· def __getitem__(self, index):
· · return chr(ord(str.__getitem__(self, index))+1)
print filter(lambda x: x>1, tuple2((1, 2)))
print filter(lambda x: x>"a", str2("ab"))
this prints:
(2,)
bc
i.e. the overwritten __getitem__ is ignored in the
first case, but honored in the second.
|
|
| Date |
User |
Action |
Args |
| 2007-08-23 14:09:57 | admin | link | issue665835 messages |
| 2007-08-23 14:09:57 | admin | create | |
|