| |
comp.lang.python |
... > x = C.__new__(C, 23) > x = C.__new__(C, 23) > to comply with the current implementation (I used Python 2.4). class B(A): you'll see that while b.__init__() would print 'from instance', x = C.__new__(C, 23) and this is how I plan to have it in the 2nd edition. Alex
> x=C(23) is equivlent to the following code:
> if isinstance(x, C): C.__init__(x, 23)
...
> the "Nutshell" example should be changed to
> if isinstance(x, C): x.__init__(23)
are taken from the type, NOT from the instance as the latter is saying.
E.g, if you change class B into:
def __init__(self):
print "init B"
def f(): print 'from instance'
self.__init__ = f
instantiating A will not. I think the right correction to the Nutshell
is therefore:
if isinstance(x, C): type(x).__init__(x, 23)