__getattribute__ for class object

Dan dan at cellectivity.com
Fri Aug 12 07:41:35 EDT 2005


> > but if i want to have a __getattribute__ for class attributes
>
> Read something on metaclasses.

Depending on what you want to do, it might be better to use properties
instead:

  class Meta(type):
     x = property(lambda klass: 'Called for '+str(klass))

  class Foo(object):
     __metaclass__=Meta

  print Foo.x

-- 
  Do I know what's in this bill? Are you kidding? Only God knows...
      - U.S. Senator Robert Byrd, when asked if he knew the
        contents of a $520 billion, 4000-page spending bill





More information about the Python-list mailing list