__init__ is the initialiser

Ethan Furman ethan at stoneleaf.us
Fri Jan 31 21:45:19 EST 2014


On 01/31/2014 06:28 PM, Terry Reedy wrote:
>
> Construct a house:
>    Clear and grade house site.
>    Bring in power and water.
>    Built temporary structures.
>    Built foundation.
>    Built house on foundation.
>
> For most classes, __new__ stops with the foundation -- the bare object object (with the class name slapped onto it). A
> *house* is not constructed until the house is constructed on top of the foundation.

On the ground programming has the dividing line at:

   immutable objects --> everything done in __new__

   mutable objects --> everything done in __init__

Typically, immutable objects are not created in Python code because, well, it's really dang hard (__slots__, anyone?), 
but one still needs to understand how __new__ and __init__ go together to do the more interesting stuff (such as having 
__new__ return a dynamically selected subclass, which still needs to be (or not be) __init__ed).

--
~Ethan~



More information about the Python-list mailing list