__init__ is the initialiser

Terry Reedy tjreedy at udel.edu
Sat Feb 1 04:16:59 CET 2014


On 1/31/2014 7:13 PM, Ethan Furman wrote:
> On 01/31/2014 03:43 PM, Ned Batchelder wrote:
>> On 1/31/14 6:05 PM, Ben Finney wrote:
>>> Ned Batchelder writes:
>>
>> I'm not hoping to change any official terminology. I just think that
>> calling __init__ anything other than a constructor
>> is confusing pedantry.  It is a constructor, and Python constructors
>> work differently than those in C++ and Java.
>
> And I would say the opposite.  __init__ is not creating anything,

As you pointed out in a different response, Python has one default, 
two-phase constructor. type.__call__. Typically, .__new__ allocates a 
generic object (with one customization as to class). .__init__ creates, 
from that mostly generic object, a customized instance of class C with 
the minimal attributes needed to be an instance of C, with value 
specific to the instance.

Creating a painting on canvas has two similar phases. Prepare a generic 
blank canvas stretched on a frame and coated with a white undercoat. 
Paint a particular picture. Would you say that the second step is not 
creating anything?

-- 
Terry Jan Reedy




More information about the Python-list mailing list