First page Back Continue Last page Overview Graphics

Metaclasses

Principially, metaclasses are defined like any other Python class, but they are classes that inherit from „type“.

Another difference is, that a metaclass is called automatically, when the class statements using a metaclass ends.

In other words: If no „metaclass“ keyword is passed after the base classes of the class header, the __call__ method will be called. If a metaclass keyword is used on the other hand, the class assigned to it will be called instead of „type“.

Now we create a very simple metaclass. It‘s good for nothing, except that it will print the content of its arguments in the __new__ method.