Mystery Theater New Style Classes
vze4rx4y at verizon.net
Thu Jul 24 21:59:59 CEST 2003
> Predict the output:
> class A(int):
> classval = 99
> def __init__(self, val = 0):
> if val:
> self = val
> self = A.classval
> print a,b
The output would be 3 and 0.
I think the point is that the value binding occurs
in the int.__new__ classmethod and that self
already has its value when __init__ is called.
Assigning the local variable, self, has no effect.
The other tidbit is that int() with no args returns zero.
More information about the Python-list