On Dec 6, 5:29 pm, Matt Saxton <m...@scotweb.co.uk> wrote: > You can use a metaclass for this: > > >>> class BaseMeta(type): > ... def __new__(mcs, name, bases, dict): > ... dict['key'] = 'Key_for_%s' % name > ... return type.__new__(mcs, name, bases, dict) > ... > >>> class Base: > ... __metaclass__ = BaseMeta > ... > >>> class Inherited(Base): > ... pass > ... > >>> Base.key > 'Key_for_Base' > >>> Inherited.key > 'Key_for_Inheritor'
I like that! I tend to think of metaclasses as for "complicated" stuff. It's nice to see a simple use. Paul -- http://mail.python.org/mailman/listinfo/python-list