__init__ not a "constructor" ?

Roman Suzi rnd at onego.ru
Mon Aug 13 17:03:05 EDT 2001


On Mon, 13 Aug 2001, Kirby Urner wrote:

>
>I notice the author of the Dive Into Python tutorial cautions
>that __init__ is not trully a class constructor, as by the time
>it's invoked, an instance already exists (hence the argument
>'self', hence the fact that classes don't need an __init__
>method).

It is constructor:

\begin{methoddesc}[object]{__init__}{self\optional{, args...}}
Called when the instance is created.  The arguments are those passed
to the class constructor expression.  If a base class has an
\method{__init__()} method the derived class's \method{__init__()} method
must
explicitly call it to ensure proper initialization of the base class
part of the instance, e.g., \samp{BaseClass.__init__(\var{self},
[\var{args}...])}.
\indexii{class}{constructor}

If I understood recent developments of Python, there will soon one more
constructor: __new__ to give raw instance (whatever that means).

I am not sure if "constructor" is a strictly defined term, though.
It's some routine which constructs object of a class.
__new__ do it. So continues __init__. They are for different
construction stages.

Anybody?

>I'm wondering if it's therefore considered faux pax to refer to
>the constructor of a Python user-defined class, meaning __init__,
>or if there's some tacit liberalizing of "constructor" (it's meaning)
>going on, such that this usage is acceptable.

Sincerely yours, Roman Suzi
-- 
_/ Russia _/ Karelia _/ Petrozavodsk _/ rnd at onego.ru _/
_/ Monday, August 13, 2001 _/ Powered by Linux RedHat 6.2 _/
_/ "I distinctly remember forgetting that." _/





More information about the Python-list mailing list