Why do we nned both - __init__() and __new__()

Gregory Ewing greg.ewing at canterbury.ac.nz
Fri Sep 8 21:19:51 EDT 2017


dieter wrote:
> In the general case, constructing an object can be split into two
> subtasks: obtain a raw piece of storage able to manage the object's state;
> initialize the object's state. The first subtask is handled by "__new__",
> the second by "__init__".

Except that's not quite correct, because the cases where
you need to override __new__ are ones where it does *more*
than just allocate storage.

-- 
Greg



More information about the Python-list mailing list