__init__ is the initialiser

Ned Batchelder ned at nedbatchelder.com
Sat Feb 1 03:56:12 CET 2014


On 1/31/14 9:28 PM, Terry Reedy wrote:
>>>>  Most classes have __init__, only very very few have __new__.
>
> *Every* class has .__new__. Mutable builtins and almost all user classes
> inherit .__new__ from object. Every class also has .__init__, but it is
> mainly inherited from object by immutable builtins.
>  >>> tuple.__init__
> <slot wrapper '__init__' of 'object' objects>
> User classes lacking .__init__ usually inherit it from something other
> than object. So objects are constructed by first calling .__new__ and
> then passing the result to .__init__. The Python 3 doc should say so.

Sorry, I wasn't clear.  I meant (as many have understood) that most 
user-defined classes define __init__, and that very very few define __new__.

-- 
Ned Batchelder, http://nedbatchelder.com




More information about the Python-list mailing list