__init__ not a "constructor" ?

Alex Martelli aleax at aleax.it
Tue Aug 14 04:22:39 EDT 2001


"Rainer Deyke" <root at rainerdeyke.com> wrote in message
news:114e7.30334$c8.9974672 at news1.denver1.co.home.com...
    ...
> > class A:
> >     def __init__(self, *args):
> >         # do stuff
> >
> > ... is roughly analogous to C++'s constructors, if you don't count C++'s
> > implicit passing of the object.
>
> One important difference is that Python gives more control over the
> construction process.  For example, in C++ the constructors of all base
> classes are always called before the constructor body is entered.  A
Python
> '__init__' method can choose if, when, and in what order the base class
> '__init__' methods should be called.

...so Python's constructors are closer to Java, where superclass
construction is also non-implicit (Java has single inheritance,
and therefore the handy 'super' keyword, but it seems to me that
the implicit vs explicit distinction is more important here).


Alex






More information about the Python-list mailing list