[Pyrex] Calling Pyrex from another Python module

konrad.hinsen at laposte.net konrad.hinsen at laposte.net
Thu Jan 4 06:55:44 UTC 2007


On 03.01.2007, at 16:49, Nicholas Riley wrote:

> I've got a large Python extension module written in C (most of which I
> didn't write) which I'd like to have call functions in my module built
> with Pyrex.  I've already got C code written to interface with my
> Pyrex module, which works fine, but it builds into the same .so.  I'd
> prefer to keep the two modules separate if possible.
>
> Is there an example (or at least discussion) of how to do this
> somewhere?  I've been reading both the Python and Pyrex documentation
> and see lots of mentions to things that come close.

Much of my code does C-function calls between two extension modules  
written in C. Each module makes its callable C functions visible  
through a CObject. The calling module obtains this CObject through  
the standard import mechanism. At some time I wrote a section about  
this mechanism for the "Python extending and embedding" manual; I  
suppose it's still in there.

A good example is the module Scientific_netcdf in ScientificPython.  
It imports the C API of Numeric, and exports its own, so you can see  
both sides in action.

I have never used this approach with Pyrex, but I don't see why it  
shouldn't be possible, given that Pyrex can create pretty much any C  
code.

Konrad.
--
---------------------------------------------------------------------
Konrad Hinsen
Centre de Biophysique Moléculaire, CNRS Orléans
Synchrotron Soleil - Division Expériences
Saint Aubin - BP 48
91192 Gif sur Yvette Cedex, France
Tel. +33-1 69 35 97 15
E-Mail: hinsen at cnrs-orleans.fr
---------------------------------------------------------------------





More information about the Pyrex mailing list