ASPN ActiveState Programmer Network
  ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups | Web Services
SEARCH
advanced | search help

Reference
ActivePython 2.4
Python Documentation
Extending and Embedding
2. Defining New Types
2.2 Type Methods
2.2.1 Finalization and De-allocation
2.2.2 Object Presentation
2.2.3 Attribute Management
2.2.4 Object Comparison
2.2.5 Abstract Protocol Support
2.2.6 More Suggestions

MyASPN >> Reference >> ActivePython 2.4 >> Python Documentation >> Extending and Embedding >> 2. Defining New Types >> 2.2 Type Methods
ActivePython 2.4 documentation

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 data type, 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;
    }
See About this document... for information on suggesting changes.

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState 2004 All rights reserved