readonly class attribute ?

Bruno Desthuilliers bdesth.quelquechose at
Tue Mar 15 23:28:59 CET 2005

Simon Percivall a écrit :
> Start the attribute name with "_" and don't document it. If clients
> mess with it, they're to blame.

The problem is that client code must *define* this attribute when 
subclassing BaseClass - and that's (well, in most case that should be) 
the only place where they have to deal with it (unless they want to do 
mumbo-jumbo thangs, in which case that's not my problem anymore !-).

What I want is to prevent client code to accidentally mess with it, and 
have strange bugs that they may have hard time to fix. At the same time, 
  I want to have the cleanest syntax for the subclass declaration. In 
fact, in most cases, the client code should not have much more to do 
than defining a handfull of class attributes to end up with a 
taylor-made fully functional subclass.


More information about the Python-list mailing list