Calling parent constructor with different argument list

Mark Lawrence breamoreboy at yahoo.co.uk
Fri Aug 14 19:19:40 EDT 2009


pinkisntwell wrote:
> class Vertex(tuple):
>     pass
> 
> class Positioned_Vertex(Vertex):
> 
>     def __init__(self, a, b):
def __init__(self, a): # just take out b
>         Vertex.__init__(a)
> 
> a=Positioned_Vertex((0,0,0), 1)
a=Positioned_Vertex( ( (0,0,0), 1) ) # and add a pair of brackets
print a
> 
> This gives:
> 
> TypeError: tuple() takes at most 1 argument (2 given)
> 
> It looks like the explicit call to Vertex.__init__ is never made and
> Vertex.__init__ is implicitly called when a Positioned_Vertex is
> created. Is there a way to work around this and call the constructor
> with the intended argument list?
Simplest way to get it to work is above using Python 2.6.2 on Windows. 
I'm sure there are variations depending on your use case, but I'll leave 
that to the experts.

-- 
Kindest regards.

Mark Lawrence.




More information about the Python-list mailing list