![]()
|
2.2.6 More Suggestions
Remember that you can omit most of these functions, in which case you
provide In the Objects directory of the Python source distribution, there is a file xxobject.c, which is intended to be used as a template for the implementation of new types. One useful strategy for implementing a new type is to copy and rename this file, then read the instructions at the top of it. There are type definitions for each of the functions you must provide. They are in object.h in the Python include directory that comes with the source distribution of Python.
In order to learn how to implement any specific method for your new
datatype, do the following: Download and unpack the Python source
distribution. Go the the Objects directory, then search the
C source files for When you need to verify that the type of an object is indeed the object you are implementing and if you use xxobject.c as an starting template for your implementation, then there is a macro defined for this purpose. The macro definition will look something like this:
And, a sample of its use might be something like the following:
|