Description of constructor parameter meaning of type in Python

Source: Internet
Author: User
Tags constructor in python

This article mainly introduces the definition of the constructor parameters of type in Python, this paper uses an example of encoding to explain the function and meaning of the parameters of Python type, and the friends who need it can refer to

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

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.