The curious behavior of integer objects
Robert Kern
robert.kern at gmail.com
Mon Jan 15 17:52:52 EST 2007
Jim B. Wilson wrote:
> Am I nuts? Or only profoundly confused? I expected the this little script
> to print "0":
>
> class foo(int):
> def __init__(self, value):
> self = value & 0xF
That statement only rebinds the local name self to something else. It does not
modify the object at all or change the result of instantiating foo(). You need
to override __new__ to get the behavior that you want.
http://www.python.org/download/releases/2.2.3/descrintro/#__new__
--
Robert Kern
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
More information about the Python-list
mailing list