Inheritable computed class attributes?

kj no.email at please.post
Fri Apr 30 18:34:08 EDT 2010


In <4bdb4e4f$1 at dnews.tpgi.com.au> Lie Ryan <lie.1296 at gmail.com> writes:

>class MetaSpam(type):
>    @property
>    def Y(cls):
>        return cls.X * 3

>class Spam(object):
>    __metaclass__ = MetaSpam


>and there we go:

>>>> class Ham(Spam):
>...     X = 7
>...
>>>> class Eggs(Spam):
>...     X = '.'
>...
>>>> Ham.Y; Eggs.Y
>21
>'...'


!!!hmmm!!!

That's very interesting!  I did not know about metaclasses; I need
to learn more about them.  Thanks for the pointer!

~K



More information about the Python-list mailing list