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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access