__getattribute__ for class object

Paolino paolo_veronelli at libero.it
Fri Aug 12 07:28:23 EDT 2005


Sylvain Ferriol wrote:
> hello
> when i define __getattribute__ in a class, it is for the class instances
> but if i want to have a __getattribute__ for class attributes
> 
> how can i do that ?
> 

Skating on thin ice eh.Read something on metaclasses.


class Meta(type):
   def __getattribute__(klass,attr):
     value=type.__getattribute__(klass,attr)
     print attr,'==',value
     return value

class Foo(object):
   __metaclass__=Meta
   a=2

Foo.a

Paolino



More information about the Python-list mailing list