Question to python C API

Diez B. Roggisch deets at
Thu Apr 16 15:01:22 CEST 2009

>         it is possible to write C and python code into the 
>         same file ?

Not as such.

And JNI is an atrocity, btw.

But what you can do (if you have a pure C-API, no C++) is to completely 
ditch the C from the equation and go for ctypes. This allows you to 
easily wrap the C-functions in pure python, and then write a simple 
layour for OO-goodness around it.

Callbacks from C to python work without a hitch, and generally it's 
really cool to work with ctypes.

You can also try & use Cython, a Python-like language that makes 
bridging between C and Python easier. I personally don't have any 
experience with it (only it's predecessor Pyrex, which worked well for 
me) - but to be honest: as long as you aren't in there for speed (Cython 
can make things faster, if you restrict yourself to the subset the 
language supports), ctypes is the easiest thing to go for. No compiler, 
no hassle.


More information about the Python-list mailing list