Description of type constructor parameters in Python: python Constructor

Source: Internet
Author: User

Description of type constructor parameters in Python: python Constructor

The test code is as follows:
Copy codeThe 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:
Copy codeThe Code is as follows:
INFO: root: cls is: <class '_ main _. ModelMetaClass'>
INFO: root: name is: Model
INFO: root: base is :( <type 'dict '> ,)
INFO: root: attrs is: {'_ module _': '_ main _', '_ metaclass __': <class '_ main __. modelMetaClass '>,' _ init _ ': <function _ init _ at 0x025C76F0>}

The conclusion is obvious. Cls is the name of the current class, that is, the class itself. Name refers to the class that points to ModelMetaClass through the _ metaclass _ attribute, that is, the class to be instantiated. ModelMetaClass intercepts the class instantiation. Base is the base class of the class to be instantiated. Attrs is a set of attributes of the class to be instantiated.

Related Article

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.