I want to automatically run a class method defined in a base class on any derived class during the creation of the class. For instance:
class Base(object):
@classmethod
def runme():
print "I am being run"
def __metclass__(cls,parents,attributes):
clsObj = type(cls,parents,attributes)
clsObj.runme()
return clsObj
class Derived(Base):
pass:
What happens here is that when Base is created, ''runme()'' will fire. But nothing happens when Derived is created.
The question is: How can I make ''runme()'' also fire when creating Derived.
This is what I have thought so far: If I explicitly set Derived's metaclass to Base's, it will work. But I don't want that to happen. I basically want Derived to use the Base's metaclass without me having to explicitly set it so.