This article mainly introduces the definition of the constructor parameters of type in Python, this paper uses an example of encoding to explain the function and meaning of the parameters of Python type, and the friends who need it can refer to
The test code is as follows:
The code is as follows:
Class Modelmetaclass (Type):
def __new__ (cls,name,base,attrs):
Logging.info ("CLS is:" +str (CLS))
Logging.info ("name is:" +STR (name))
Logging.info ("Base is:" +str (base))
Logging.info ("Attrs is:" +str (Attrs))
Return type.__new__ (Cls,name,base,attrs)
Pass
Pass
Class Model (Dict):
__metaclass__ = Modelmetaclass
def __init__ (self):
Pass
Pass
def main ():
M=model ()
if __name__ = = ' __main__ ':
Main ()
Test results:
The code is as follows:
INFO:ROOT:CLS is:
INFO:root:name Is:model
INFO:root:base is: ( ,)
INFO:root:attrs is:{' __module__ ': ' __main__ ', ' __metaclass__ ': , ' __init__ ': }
The conclusion is obvious. The CLS is the name of the current class, that is, the class itself. Name is the class that points to modelmetaclass through the __metaclass__ property, that is, the class to instantiate, and Modelmetaclass intercepts the instantiation of the class. Base is the base class for the class to instantiate. Attrs is a collection of properties for the class to instantiate.