GNU Info

Info Node: (python2.1-api.info)Objects

(python2.1-api.info)Objects


Next: Exceptions Prev: Include Files Up: Introduction
Enter node , (file) or (file)node

Objects, Types and Reference Counts
===================================

Most Python/C API functions have one or more arguments as well as a
return value of type `PyObject*'.  This type is a pointer to an opaque
data type representing an arbitrary Python object.  Since all Python
object types are treated the same way by the Python language in most
situations (e.g., assignments, scope rules, and argument passing), it
is only fitting that they should be represented by a single C type.
Almost all Python objects live on the heap: you never declare an
automatic or static variable of type `PyObject', only pointer variables
of type `PyObject*' can be declared.  The sole exception are the type
objects ; since these must never be deallocated, they are typically
static `PyTypeObject' objects.

All Python objects (even Python integers) have a "type" and a
"reference count".  An object's type determines what kind of object it
is (e.g., an integer, a list, or a user-defined function; there are
many more as explained in the ).  For each of the well-known types
there is a macro to check whether an object is of that type; for
instance, `PyList_Check(A)' is true if (and only if) the object pointed
to by A is a Python list.

Reference Counts
Types

automatically generated by info2www version 1.2.2.9