On Apr 12, 8:36 pm, Charles D Hixson <[EMAIL PROTECTED]> wrote: > I'm trying to construct read-only variables at the class level. I've > been unsuccessful. Any suggestions? > > Mixing @classmethod and @property doesn't appear to produce workable > code. Ditto for mixing @classmethod and __getattr__. (The property > approach compiles, but execution says that you can't execute properties.) > > I've got a rather large number of variables, so I don't want to define > function accessors for each of them, and I *REALLY* don't want to have > to access them as functions rather than variables or properties.
Metaclasses, of course! >>> class MetaX(type): ... @property ... def spam(self): return 'eggs' ... >>> class X(object): ... __metaclass__ = MetaX ... >>> X.spam 'eggs' >>> HTH -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list