[Tutor] combining c and python
oscar.j.benjamin at gmail.com
Mon Sep 17 19:20:26 CEST 2012
On 2012-09-17, Bala subramanian <bala.biophysics at gmail.com> wrote:
> I code in python and so far able to write simple scripts for my needs.
> Now i want to try the combination of c and python.
> 1) could someone please suggest me some good documentation on how
> python and C can be combined. Some tutorials with simple examples.
> 2) If i know that a specific part (loop in my case) within my python
> script consumes more processing time, is it possible to implement/use
> 'c' only for that part. Precisely using C within python ? Any link for
> documentation on such implementation would be of great help to me.
I would use cython for this:
Cython allows you to write something that looks a lot like a python module but
that gets translated into c, compiled with a c compiler and then turned into
an extension module. Once compiled the extension module can be used from other
scripts/modules just like an ordinary python module. But the code that was
written in that module will often run a lot faster than ordinary python code
particularly if you have an intensive but simple inner loop.
More information about the Tutor