What's your first choice if you have to write a C module for python?

Christian Heimes lists at cheimes.de
Tue Aug 26 18:14:18 EDT 2008


一首诗 wrote:
> Hi all,
> 
> I read this interesting post comparing Boost.Python with Pyd:
> 
> http://pyd.dsource.org/vsboost.html
> 
> What's your opinion about it?
> 
> What's your first choice when you have write a C/C++ module for Python?

I'm using handwritten C code or Cython/Pyrex to create Python C 
extensions. Handwritten C code is sometimes required when you need full 
control over the C code and performance (speed or memory) is crucial to 
the project. Handwritten C code is the only option when you need 
readable, debugable C code.

However Cython is great for most applications these days. It's my 
preferred way to wrap small to large libraries, I was able to get quick 
and sufficient results in a matter of minutes.

ctypes is nice for small applications but I don't use it for serious 
work. It's too fragile across computer architectures, e.g. big/little 
endian machines or more important i386, AMD64/Unix and AMD64/Win32 
operation systems.

SIP claims to be the fastest and easiest system to wrap C++ code. The 
Cython wiki says it's about 40% faster than SWIG.

Christian




More information about the Python-list mailing list