Defining Extension Types: Tutorial — Python 3.16.0a0 documentation

docs.python.org

Tin mới

Using the C API: Assorted topics

Defining Extension Types: Assorted Topics

Python Module Index

3.16.0a0 Documentation

Extending and Embedding the Python Interpreter

pydoc: Documentation generator and online help system.

So, if you want to define a new extension type, you need to create a new type object.

pickle: Convert Python objects to streams of bytes and back.

So, if you want to define a new extension type, you need to create a new type object.

PyTypeObject.tp_itemsize

So, if you want to define a new extension type, you need to create a new type object.

PyType_GenericNew()

So, if you want to define a new extension type, you need to create a new type object.

Adding data and methods to the Basic example¶

Let’s extend the basic example to add some data and methods. Let’s also make the type usable as a base class. We’ll create a new module, custom2 that adds these capabilities:

Adding data and methods to the Basic example¶

Let’s extend the basic example to add some data and methods. Let’s also make the type usable as a base class. We’ll create a new module, custom2 that adds these capabilities:

Adding data and methods to the Basic example¶

Let’s extend the basic example to add some data and methods. Let’s also make the type usable as a base class. We’ll create a new module, custom2 that adds these capabilities:

Adding data and methods to the Basic example¶

Let’s extend the basic example to add some data and methods. Let’s also make the type usable as a base class. We’ll create a new module, custom2 that adds these capabilities:

Adding data and methods to the Basic example¶

Let’s extend the basic example to add some data and methods. Let’s also make the type usable as a base class. We’ll create a new module, custom2 that adds these capabilities:

Supporting cyclic garbage collection¶

Python has a cyclic garbage collector (GC) that can identify unneeded objects even when their reference counts are not zero. This can happen when objects are involved in cycles. For example, consider:

Subclassing other types¶

It is possible to create new extension types that are derived from existing types. It is easiest to inherit from the built in types, since an extension can easily use the PyTypeObject it needs. It can be difficult to sha

Subclassing other types¶

It is possible to create new extension types that are derived from existing types. It is easiest to inherit from the built in types, since an extension can easily use the PyTypeObject it needs. It can be difficult to sha