Defining New Types
New types of objects can also be defined in extension modules. However, this process is considerably more advanced than simply accessing a few C functions. Because of this complexity, you should consider implementing a new type only in the following situations:
The type is not easily constructed from existing Python types.
The type requires interaction with the operating system or another special feature not provided by the interpreter or the standard library.
The type hasn’t already been implemented elsewhere. For example, efficient matrix types have already been implemented, so it would make little sense to reinvent them. It’s always a good idea to check the Python libraries and newsgroups before implementing a new type. The ...
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