Description of the type constructor parameter in Python

Source: Internet
Author: User

The test code is as follows:

1 classModelmetaclass (type):2     def __new__(cls,name,base,attrs):3Logging.info ("CLS is:"+str (CLS))4Logging.info ("name is:"+STR (name))5Logging.info ("Base is:"+Str (base))6Logging.info ("Attrs is:"+str (attrs))7         returnType.__new__(cls,name,base,attrs)8         Pass9     PassTen  One classModel (dict): A     __metaclass__=Modelmetaclass -     def __init__(self): -         Pass the     Pass -  - defMain (): -m=Model () +  - if __name__=='__main__': +Main ()

Test results:

1INFO:root:cls is:<class '__main__. Modelmetaclass'>2INFO:root:name is: Model3INFO:root:base is:(<type'Dict'>,)4INFO:root:attrs is:{'__module__':'__main__','__metaclass__': <class '__main__. Modelmetaclass','__init__': <function__init__At 0x025c76f0>}

The conclusion is obvious. The CLS is the name of the current class, that is, the class itself. Name is a class that points to modelmetaclass through the __metaclass__ property, which 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.

Description of the type constructor parameter in Python

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.