memberfunctions

Courageous jkraska1 at san.rr.com
Sun Apr 22 12:39:41 EDT 2001


>I've read the tutorial about adding new types with Python/C, but how to add
>memberfunctions and membervariables ?

Get a python source distribution. In the objects/ directory you will find a file:
XXOBJECT.C. This is an example of how to create what you want.

You should also read the "Extending & Embedding" section at http://www.python.org.

The book __Essential Python Reference__ has the best section on extending
and embedding I've seen so far.

When you first look at the object-creation stuff, you may think it looks a bit
hard. It's not really. It's just verbose, and very formulaic. The good news is,
once you've learned one object, you've pretty much learned them all. There's
little variation between objects, except with regards to the choice of interfaces
(list, et al) you make.

You may eventually want to read the code for Python's dictionary and list:
LISTOBJECT.C and DICTOBJECT.C. Python's own containers are written
in the very same code one uses to create a custom user object.

Pay careful attention to reference counting. The smallest error in this respect
will either cause the interpreter to crash or assure that your object is NEVER
freed (during the life of the interpreter, anyway).

C//





More information about the Python-list mailing list