Wrapping C with Python

RPM1 rpm9deleteme at earthlink.net
Tue Aug 5 00:45:54 CEST 2008


Anish Chapagain wrote:
> On 4 Aug, 14:14, brad <byte8b... at gmail.com> wrote:
>> RPM1 wrote:
>>
>> ...
>>
>>> Basically you just compile your C code as a regular C code dll.  ctypes
>>> then allows you to access the functions in the dll very easily.
>> Does that work with C++ code too or just C?
> 
> Hi..
> I havenot tried..before with dll, is there any help material and for
> me my API in C has almost 20 c files, so will it be feasible
> 
> anish

It is worth looking into it.  I found ctypes to be very easy.  I had the 
example up and running in minutes.  I have also figured out how to do 
things like return arrays to Python.  It isn't that hard.  I like the 
fact that I don't have to think about reference counting or PyObjects 
etc.  If you are doing simple function calls ctypes is very easy.

My C code looks like C code.  It has no Python stuff at all.  My Python 
code has just a few calls to the ctypes module.  I guess that's one 
thing I like about it is that my C code looks like C code and my Python 
code looks like Python code, (not much spilling over).

I'm sure it's not perfect, but it seems a lot easier than SWIG to me.

Patrick



More information about the Python-list mailing list