macrocosm at fastmail.fm
Wed Oct 6 22:11:00 CEST 2004
Jeff Shannon wrote:
> 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.
> Jeff Shannon
> Credit International
Cool. This seems then to have the same functionality as ObjC messages.
I am beginning to like Python more and more.
More information about the Python-list