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

Ulrich Eckhardt eckhardt at satorlaser.com
Tue Aug 26 12:04:58 EDT 2008


一首诗 wrote:
> 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?

There is no such thing as a C/C++ language. Seriously, both are really
different and require different approaches. That said, when writing a C++
module I use Boost.Python, for one because Boost is already part of many
C++ projects but also because it is simply very easy and convenient to use.

There is another alternative, ctypes, which also works but it IMHO brings
many of the disadvantages of C to Python. In particular those are manual
resource management and lack of exceptions. Looking at Boost.Python though,
you can simply throw a C++ exception and it gets mapped to a Python
exception, and resource management is also a non issue since you can make
ownership transfers explicit.

Now, concerning pyd, I think you are comparing apples to oranges. If you had
asked which language I would chose to write a Python plugin, that would
have been a totally different thing. To that, the answer is in order of
preference:
 1. Python ;)
 2. C++ with Boost.Python
 3. C with ctypes

cheers

Uli


-- 
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932




More information about the Python-list mailing list