calling upper constructor

Marc Poulin mpoulin at verinet.com
Thu Jan 31 21:24:20 EST 2002


In article <3c5a0f42$0$2197$7586b60c at news.frii.com>, "Marc Poulin"
<mpoulin at verinet.com> wrote:

> class abc(Base):
>         def __init__(self):
>                 print "entering abc.__init__"
>                 Base.__init__(self)
>                 print "leaving abc.__init__"

One further note: if you are coming from a C++ background, you
know that C++ guarantees that base classes are fully constructed
before the constructor of the derived class is called. If that is
the behavior you want, you must be sure the "Base.__init__(self)"
line is the very first line of code, like this:

class abc(Base):
	def __init__(self):
		Base.__init__(self)
		## Base is now fully constructed
		##
		## The rest of abc.__init__ follows ...



More information about the Python-list mailing list