jeff at ccvcorp.com
Wed Oct 6 21:13:08 CEST 2004
Arich Chanachai wrote:
>> You mean some refinement of this sort of thing:
>> class X(object):
>> a = "lives in X"
>> def __getattr__(self, name):
>> return getattr(U,name)
>> class U(object):
>> b = "lives in Y"
>> x = X()
>> print x.a
>> print x.b
> Sure, but what if I dynamically (at runtime) extend X to include
> variable b. Will it then print X.b or still U.b?
In this case, as I understand it, adding an attribute b to either x (the
instance) or X (the class) will cause x.b to resolve to the new
attribute, and *not* to U.b -- attributes are dynamically looked up each
time they are used, and __getattr__() is called only when the standard
lookup methods (instance, class, superclass, ...) fail.
More information about the Python-list