Website hosting service by

 Back to Index

2.2.6 More Suggestions

Remember that you can omit most of these functions, in which case you provide 0 as a value. 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 Objects directory, then search the C source files for tp_ plus the function you want (for example, tp_print or tp_compare). You will find examples of the function you want to implement.

When you need to verify that an object is an instance of the type you are implementing, use the PyObject_TypeCheck function. A sample of its use might be something like the following:

    if (! PyObject_TypeCheck(some_object, &MyType)) {
        PyErr_SetString(PyExc_TypeError, "arg #1 not a mything");
        return NULL;


2002-2004 Web Hosting Service


Disclaimer: This documentation is provided only for the benefits of our hosting customers.
For authoritative source of the documentation, please refer to


Domain registration - Domain registration, register domain or transfer domain name from only $5.95/yr

Cheap domain registration -
Register domain name and
domain transfer from $7.95/year only