hmm, lets call it: generic init problem ['LBBW': checked]
Michele Simionato
michele.simionato at poste.it
Sat Feb 21 05:01:15 EST 2004
"Holger Joukl" <Holger.Joukl at LBBW.de> wrote in message news:<mailman.70.1077206479.27104.python-list at python.org>...
> I just started out with python 2.3, so I might be totally wrong,
> but does this work?
>
> >>> class one(object):
> ... def init (self, *args, **kwargs):
> ... super(self. class , self). init ()
> ...
> >>> one()
> < main .one object at 0x1dd190>
This is tempting, but breaks under inheritance:
class A(object):
def __init__ (self):
print "A.__init__"
super(self.__class__, self).__init__()
class B(A):
def __init__ (self):
print "B.__init__"
super(self.__class__, self).__init__()
b=B()
Here B.__init__ will call A.__init__ which will call itself, generating
an infinite loop. The reason is that in A.__init__, when self=b, one
has super(self.__class__,self).__init__() == super(B,b).__init__()
which will call A.__init__(b) again and again.
Michele Simionato
More information about the Python-list
mailing list