overriding a tuple's __init__
Simon Burton
simonb at webone.com.au
Mon Aug 18 04:35:22 EDT 2003
On Mon, 18 Aug 2003 08:24:21 +0000, Duncan Booth wrote:
> Simon Burton <simonb at webone.com.au> wrote in
> news:pan.2003.08.18.07.37.44.108933 at webone.com.au:
>
>>>>> class pair(tuple):
>> ... def __init__(self,a,b):
>> ... tuple.__init__(self, (a,b) )
>> ...
>>>>> a=pair(1,2)
>> Traceback (most recent call last):
>> File "<stdin>", line 1, in ?
>> TypeError: tuple() takes at most 1 argument (2 given)
>>>>>
>>
>> What gives? (yes it works with a list, but i need immutable/hashable)
>
> You need to override __new__ instead of __init__:
>
:) I need to grow a brain. thanks Duncan.
Simon.
More information about the Python-list
mailing list