A. Premises:
In Python everything is an object, either a class object or a meta-class object, and the type meta-class is its own object. An inheritance hierarchy is represented as a type (meta-Class)--Class (built-in and user-defined) and an instance of the class.
Two. Purpose:
When you create a class, you automatically change the class, in other words, create something like this.
Three. __metaclass__
You can create a class by specifying __metaclass__ to use a user-defined meta-class.
Class Statement parsing order :
Class Myclass (object): Pass
MyClass inside of __metaclass__----__metaclass__ in the parent class (object)---The default type in the module
Four. How to use:
1.__metaclass__ = Callablefunc
1 def Callablefunc (classname, Bases, DCT):2 ... 3 Data Processing 4 ... 5 return Type (classname, bases, NEWDCT)
2 __metaclass__ = Custom meta-Class
1 class Mymeta (type): 2 def __new__ (CLS, classname, Bases, DCT): 3 ... 4 Data processing for DCT, generating NEWDCT5 ... 6 return super (MYMETA,CLS). __new__ (CLS,CLASSNAME,BASES,NEWDCT)
Python in Meta class