Another try at Python's selfishness

Terry Reedy tjreedy at udel.edu
Fri Feb 3 15:27:51 EST 2006


"Magnus Lycka" <lycka at carmen.se> wrote in message 
news:drvd56$nb3$1 at wake.carmen.se...
> n.estner at gmx.de wrote:
> Today, Python has a syntactic shortcut. If 'a' is an
> instance of class 'A', a.f(x,y,z) is a shortcut for
> A.f(a,x,y,z). If you don't use the shortcut, there is
> no magic at all, just the unusual occurence of a type
> check in Python!

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.  The 'magical' part of accessing functions 
via instances is the implementation of dynamic inheritance.

Terry Jan Reedy






More information about the Python-list mailing list