Tuple Question

V

VanL

Hello,

Why is this?
.... 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'

Thanks,

VL
 
S

Steven Bethard

VanL said:
Why is this?
... 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:
.... def __getitem__(self, name):
.... return tuple.__getitem__(self, name)
....
>>> data = (1,2,3,4,5)
>>> t = MyTuple(data)
>>> t[0]
1

Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top