Python source code analysis Reading Notes: Chapter 1-Python objects

Source: Internet
Author: User
Chapter 1-Python objects

All Python objects inherit from pyobject directly or indirectly. The definition of pyobject is simple:
Struct _ OBJECT {

Py_ssize_t ob_refcnt; // reference count
Struct pytypeobject * ob_type; // type object pointer

} Pyobject;
The reference count determines the survival of objects. Destroy object when ob_refcnt is 0

A member of a python object is a virtual function table in C ++.

Pytypeobject is also an object that inherits from pyobject. In addition to recording the object name, object size, and other data, it is a series of function pointers. Including how to reclaim the destructor of object memory, how to print objects, attribute-related functions, as well as numeric object (number) function system, sequence object function system, and ing object (mapping) functions. Set the function pointer value for different types of objects according to their own needs. For example, the integer object pyequalbject has only the number function, but not the sequence and mapping functions.

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.