__init__ explanation please

Wildemar Wildenburger lasses_weil at klapptsowieso.net
Mon Jan 14 09:37:20 EST 2008


Jeroen Ruigrok van der Werven wrote:
> To restate it more correctly: __init__ is akin to a constructor.
> 
No. See Hrvoje Niksic's reply (and Ben Finney's to which it was a reply).

__init__() /initializes/ an instance (automatically after creation). It 
is called, /after/ the instance has been constructed via the __new__() 
method.
__new__() actually /constructs/ a new instance.


> I am not entirely sure I fully understand __new__'s semantics though.
Create a new (blank) instance of a class and return it. That's all there 
is to it.


> I must not be understanding something and __new__'s documentation there is not
> that clear to me, to be honest.
> 
It is somewhat confusing at first. But just bear in mind: 99 out of 100 
times, you don't need to override __new__(). When you need it, you'll know.

/W



More information about the Python-list mailing list