這篇文章主要介紹了Python中type的構(gòu)造函數(shù)參數(shù)含義說明,本文用一個編碼實例解釋Python type的參數(shù)的作用和含義,需要的朋友可以參考下
測試代碼如下:
代碼如下:
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()
測試結(jié)果:
代碼如下:
INFO:root:cls is:
INFO:root:name is:Model
INFO:root:base is:(
INFO:root:attrs is:{‘__module__‘: ‘__main__‘, ‘__metaclass__‘:
結(jié)論就顯而易見了,