[Tutor] Calling C from Python

Danny Yoo dyoo@hkn.eecs.berkeley.edu
Fri, 20 Sep 2002 13:58:22 -0700 (PDT)


On Fri, 20 Sep 2002, Carlos Bergelin wrote:

> Hi everybody!
> I just want to know how can I do to call a C function from python?

Hi Carlos,

You can write a "wrapper" to make C functions look like Python functions.
There' s a good utility called SWIG that makes wrapper writing fairly
easy:

    http://www.swig.org/

It usually involves telling SWIG what the function interface looks like.
>From there, SWIG will generate the necessary code in C to make it
accessible to Python.


If you're curious about how all this actually works, you can take a look
at the Extending and Embedding Document:

    http://python.org/doc/current/ext/ext.html


If you have more questions, please feel free to ask.  Good luck!