Description of type constructor parameters in Python

Source: Internet
Author: User

Description of type constructor parameters in Python

This article mainly introduces the description of the type constructor parameters in Python. This article uses an encoding example to explain the role and meaning of the Python type parameters. For more information, see

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. 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.

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.