这篇文章主要介绍了Python中type的构造函数参数含义说明,本文用一个编码实例解释Python type的参数的作用和含义,需要的朋友可以参考下
测试代码如下:
代码如下:
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()
测试结果:
代码如下:
INFO:root:cls is:
INFO:root:name is:Model
INFO:root:base is:(
INFO:root:attrs is:{‘__module__‘: ‘__main__‘, ‘__metaclass__‘:
结论就显而易见了,