Writing SOME class methods in C

Daniel Haude dh at dotcom.mfs32
Wed Nov 18 02:50:30 EST 2015


Hello,

I'm trying to implement some (but not all) methods of a Python class in C.
What I've found on the Net is:
 - how to implement entire modules in C so that I can import that module and
   use the C functions (successfully done it, too).
 - how to implement entire classes in C

But I can't find any examples of modules which consist of a mixture of C and
Python, nor modules that define classes of which some members are
implemented in C, others in Python. Of course, once I have the "mixture" bit
figured out I could just define wrapper class methods that call C functions
(functions impleneted in C, that is). But I would find it rather elegant if
the C function could access the class members directly. The fact that the
C extension functions have a mandatory "PyObject *self" parameter tells me
that this must be somehow possible, but I don't know how.

I'm sure that many of the plethora of Python extension modules out there
must use the technique that I'm looking for, but I don't even know where to
start looking. Pointers are welcome.

Thanks,
robert





More information about the Python-list mailing list