Tuple Question
Steven Bethard
steven.bethard at gmail.com
Tue Dec 21 14:29:42 EST 2004
VanL wrote:
> Why is this?
>
> >>> class MyTuple(tuple):
> ... def __getitem__(self, name):
> ... return tuple.__getitem__(self, name)
> ...
> >>> data = (1,2,3,4,5)
> >>> t = MyTuple(data)
> >>> t[0]
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> File "<stdin>", line 3, in __getitem__
> TypeError: descriptor '__getitem__' requires a 'tuple' object but
> received a 'int'
What Python are you using? On Python 2.4:
>>> class MyTuple(tuple):
... def __getitem__(self, name):
... return tuple.__getitem__(self, name)
...
>>> data = (1,2,3,4,5)
>>> t = MyTuple(data)
>>> t[0]
1
Steve
More information about the Python-list
mailing list