Inheritable computed class attributes?
no.email at please.post
Fri Apr 30 16:42:58 EDT 2010
I want to define a class attribute that is computed from other
class attributes. Furthermore, this attribute should be inheritable,
and its value in the subclasses should reflect the subclasses values
of the attributes used to compute the computed attribute. I tried
X = 3
return cls.X * 3
...but Spam.Y returns <property object at 0x......>, rather than 9.
How can I define a "class property"? Is it possible at all?
Ultimately, I'd like to be able to define multiple subclasses of
X = 7
X = '.'
and have Ham.Y and Eggs.Y evaluate to 21 and '...', respectively.
More information about the Python-list