Creating a Python script 'interface' to c/c++ module

Donn Cave donn at u.washington.edu
Tue Mar 7 17:46:14 CET 2000


Quoth "Makhno" <mak at imakhno.freeserve.co.uk>:
| My problem is difficult to explain...
| I've written a module for Perl in C/C++, but user's so not call the C
| functions directly, there is a level of Perl 'wrapping' it that does various
| checks (as well as providing an OO interface). Having written the bulk of
| the module as language-independant as possible, the time has come to port it
| to Python.
|
| Unfortuanately, I can't seem to provide the Python wrapper, the way the
| modules work does not seem to let me. For example, I want to call a C
| function called my_func(). With Perl I would use the hierarchy:
| Users code->Perl wrapper->C wrapper (XS file)->C function
| with Python, I can't seem to include the second step, only
| Users code->C wrapper->C function
|
| So calling my_module.my_func() in Python, calls C code directly, there is no
| chance of executing any Python inbetween.
| The question is how do I get some Python code in there? The only way I can
| think of is writing a Python module which acts as a wrapper for the C
| module, which doesn't seem like the best way.

Eureka!  It is indeed the best way, why not?  Some of the best modules
are done exactly this way, "string" for example.

If you're desperate to do it, your C module can surely export Python
objects that in turn call back to the C module, but it's hard to think
of a design where that would be really useful.

	Donn Cave, donn at u.washington.edu



More information about the Python-list mailing list