Customizing class attribute access in classic classes

Ben Finney ben+python at benfinney.id.au
Sat Oct 29 22:16:24 EDT 2011


Geoff Bache <geoff.bache at gmail.com> writes:

> I'm wondering if there is any way to customize class attribute access
> on classic classes?

Why do that? What is it you're hoping to achieve, and why limit it to
classic classes only?

> So this works:
>
> class Meta(type):
>     def __getattr__(cls, name):
>         return "Customized " + name
>
> class A:
>     __metaclass__ = Meta
>
> print A.blah
>
> but it turns A into a new-style class.

Yes, A is a new-style class *because* it inherits from ‘type’
<URL:http://docs.python.org/reference/datamodel.html#new-style-and-classic-classes>.

Why does that not meet your needs?

-- 
 \                         Contentsofsignaturemaysettleduringshipping. |
  `\                                                                   |
_o__)                                                                  |
Ben Finney



More information about the Python-list mailing list