Another try at Python's selfishness
Jean-Paul Calderone
exarkun at divmod.com
Fri Feb 3 16:14:26 EST 2006
On Fri, 3 Feb 2006 15:27:51 -0500, Terry Reedy <tjreedy at udel.edu> wrote:
>
>"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.
I'm not sure I follow. Surely you're not suggesting that this doesn't work:
>>> class X:
... def foo(self):
... print 'X.foo', self
...
>>> class A(X):
... pass
...
>>> o = A()
>>> A.foo(o)
X.foo <__main__.A instance at 0xb7cab64c>
>>>
But I can't think what else you might mean.
>
>Terry Jan Reedy
>
>
>
>--
>http://mail.python.org/mailman/listinfo/python-list
>
More information about the Python-list
mailing list