Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Tuple Question (http://www.velocityreviews.com/forums/t339520-tuple-question.html)

VanL 12-21-2004 05:41 PM

Tuple Question
 

Hello,

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'

Thanks,

VL


Steven Bethard 12-21-2004 07:29 PM

Re: Tuple Question
 
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

Lonnie Princehouse 12-21-2004 07:34 PM

Re: Tuple Question
 
> Why is this?
It should work. Are you using an old version of Python?



All times are GMT. The time now is 12:52 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.