There are many possible things. Simplest:
The contents of the class
block are executed upon first reading.
To see this in action, this example:
class Foo(object): print "bar" def __init__(self): print "baz"
bar
will be printed when importing the module.
If the class has a specific metaclass, the metaclasses __new__ __new__
will be launched after the code class block starts.
Example:
class MyMeta(type): def __new__(mcs, name, bases, kwargs): print "I'm the metaclass, just checking in." return type.__new__(mcs, name, bases, kwargs) class Foo(object): __metaclass__ = MyMeta print "I'm the Foo class"
Output:
I'm the Foo class I'm the metaclass, just checking in.
I'm sure other bits can work as well, this is what I am familiar with.
source share