__init__ not a "constructor" ?

Evan Jones EvanJ at eyron.com
Tue Aug 14 05:11:15 EDT 2001


I would agree that __init__ is a 'constructor'.

In Java, for example, by the time 'constructor' code is called the instance
has also already been created (hence the availability of  'this' in the
constructor code) and Java classes need not define constructors, still
everyone refers to Java constructors as constructors...

Uru
Evan


> -----Original Message-----
> From:	Roman Suzi [SMTP:rnd at onego.ru]
> Sent:	ב 13 אוגוסט 2001 23:03
> To:	Kirby Urner
> Cc:	python-list at python.org
> Subject:	Re: __init__ not a "constructor" ?
> 
> 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." _/
> 
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list




More information about the Python-list mailing list