__init__ is the initialiser

MRAB python at mrabarnett.plus.com
Sat Feb 1 02:41:26 CET 2014


On 2014-02-01 01:10, Roy Smith wrote:
> In article <mailman.6233.1391214984.18130.python-list at python.org>,
>   Ethan Furman <ethan at stoneleaf.us> wrote:
>
>> I found calling __init__ the constructor very confusing.
>
> I've heard many people say this, and it's always sort of befuddled me.
>
> In C++, a constructor is really an initializer too.  By the time C++'s
> Foo::Foo() or Python's Foo.__init__() get called, memory has already
> been allocated, so I would say the object has been constructed.  Yet,
> C++ people are perfectly happy calling this "thing that takes some
> allocated hunk of memory and sets its attributes to useful values" a
> constructor[1], and Python people are not.
>
You could argue that construction is not complete until the instance
has been initialised. In the case of C++, all you have is the
initialiser, so doesn't really matter, but Python has __new__ and
__init__, so it _does_ matter.

> [1] Well, they really call it a ctor, but I chalk that up to the same
> sort of silliness that makes pythonistas pronounce "__" as "dunder" :-)
>




More information about the Python-list mailing list