readonly class attribute ?

Bruno Desthuilliers bdesth.quelquechose at free.quelquepart.fr
Tue Mar 15 17:35:14 EST 2005


Bengt Richter a écrit :
> On Tue, 15 Mar 2005 20:21:19 +0100, bruno modulix <onurb at xiludom.gro> wrote:
> 
> 
>>Hi
>>
>>How can I make a *class* attribute read-only ?
>>
(snip)
> 
> Does this help, or did I misunderstand?
> 
>  >>> class Base(object):
>  ...     class __metaclass__(type):
>  ...         def __setattr__(cls, name, value):
>  ...             raise AttributeError, 'setting %r to %r not allowed' %(name, value)

Pretty obvious, indeed !

Bengt, if we meet one day, remind me to pay you a couple of your 
favorite drink !-)



More information about the Python-list mailing list