[BangPypers] Help -- Python with C

Noufal Ibrahim noufal at gmail.com
Thu Feb 4 10:10:19 CET 2010


On Thu, Feb 4, 2010 at 2:29 PM, VIJAY KUMAR <vnbang2003 at yahoo.com> wrote:
> Hi ,
>     I wanted to call the function defined in C in to python module.
>
>      C filedummy_c_module.c contains below
>
>        int dummy_c_function(int value)
>         {
>            int ret;
>            ret = value + 5;
>            return ret;
>       }
>
>   I have Python module  dummy_p_module.py
>
>   from dummy_c_module import dummy_c_function
>   a = dummy_c_function(22)
>    print a
>
> how can we do the this. Am using Ubuntu OS.

You would either need to wrap your C file as a Python module. Docs are
available here http://docs.python.org/extending/extending.html

Or you can compile your C file into a library and use the ctypes FFI
The docs are fairly descriptive and have an included tutorial as well
http://docs.python.org/library/ctypes.html



-- 
~noufal
http://nibrahim.net.in


More information about the BangPypers mailing list