Python Macros
Jeff Shannon
jeff at ccvcorp.com
Wed Oct 6 15:13:08 EDT 2004
More information about the Python-list mailing list
Wed Oct 6 15:13:08 EDT 2004
- Previous message (by thread): Python Macros
- Next message (by thread): Python Macros
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Arich Chanachai wrote: > <SNIP> >> 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 Technician/Programmer Credit International
- Previous message (by thread): Python Macros
- Next message (by thread): Python Macros
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list