Static class properties (read-only)

Aahz aahz at
Thu Aug 7 19:47:23 CEST 2003

In article <vj4v20o2qfi7c9 at>,
Greg Brunet <gregbrunet at> wrote:
>In puzzling over classes, I'm wondering if classes can have read-only
>static properties?  I certainly seem to be able to do create static
>properties like this:
>class C(object):
>    count = 0
>    def __init__(self,s):
>        C.count += 1
>        self.Name = s
>    def __del__(self):
>        C.count -= 1
>and C.count should have a count of the number of its instances that have
>been created.  However, someone could set the value directly.  I know
>that using get/set methods, I can make a read-only property at the
>object/instance level.  Can this be done at the class level?  Thanks,

Nope.  Gotta do a metaclass.  <evil grin>
Aahz (aahz at           <*>

This is Python.  We don't care much about theory, except where it intersects 
with useful practice.  --Aahz

More information about the Python-list mailing list