cause __init__ to return a different class?

Arnaud Delobelle arnodel at gmail.com
Thu Sep 15 13:39:34 EDT 2011


On 15 September 2011 15:41, Matthew Pounsett <matt.pounsett at gmail.com> wrote:
> On Sep 15, 1:35 am, Chris Rebert <c... at rebertia.com> wrote:
>> Override __new__() instead:
>> http://docs.python.org/reference/datamodel.html#object.__new__
>
> Aha.. thanks!  The reference book I'm working from neglects to mention
> __new__, so I'd assumed __init__ was the constructor.  It hadn't
> occurred to me that python would separate the functions (I still don't
> see exactly why it would be useful to do that, but perhaps insight
> will come with time).

If you're interested in the reason, I suggest you read Guido's essay
on "new style classes" which were introduced in Python 2.2 (and are
now a good 10 years old I think):

    http://www.python.org/download/releases/2.2.3/descrintro

-- 
Arnaud



More information about the Python-list mailing list