Another try at Python's selfishness
Alex Martelli
aleaxit at yahoo.com
Fri Feb 3 23:28:41 EST 2006
Terry Reedy <tjreedy at udel.edu> wrote:
...
> As was once pointed out to me some years ago, when I wrote something
> similar, a.f() is not just a shortcut for A.f(a) [a.__class__.f(a)]. The
> latter only looks for f in the class A namespace while the former also
> looks in superclass namespaces.
Nope:
>>> class B:
... def f(self): print 'b.f'
...
>>> class A(B): pass
...
>>> a=A()
>>> a.__class__.f(a)
b.f
>>>
Inheritance applies in any lookup of an attribute in a class, just as
well as on an instance of the class.
Alex
More information about the Python-list
mailing list