O'Reilly logo

Python: Essential Reference, Third Edition by David Beazley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Defining New Python Types

One of the most advanced topics in extension building is defining new Python types in C/C++. Just as it is possible to add new functions to Python, one can add entirely new objects that behave similarly to the other built-in types, such as lists, tuples, and dictionaries.

The steps involved in adding a new type to Python are considerable and are not discussed further here. However, in practice, it rarely seems necessary to manually add a new type. For one, most of Python’s built-in types can be subclassed directly in Python. Therefore, if your only goal is to slightly modify one of the existing types, that can already be done without resorting to a C extension module. Second, a huge number of third-party extension modules ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required