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 ...
Get Python Essential Reference, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.