confused about __new__

Steven D'Aprano steve+comp.lang.python at pearwood.info
Mon Dec 26 23:53:31 EST 2011


On Mon, 26 Dec 2011 20:28:26 -0800, K. Richard Pixley wrote:

> I'm confused about the following.  The idea here is that the set of
> instances of some class are small and finite, so I'd like to create them
> at class creation time, then hijack __new__ to simply return one of the
> preexisting classes instead of creating a new one each call.

I'm surprised it works in Python3. Try this in Python 2 instead:

Foo.__new__ = staticmethod(__Foo__new__)



-- 
Steven



More information about the Python-list mailing list