Pass data from Python to C++

Russell E. Owen rowen at cesmail.net
Thu May 15 16:03:08 EDT 2008


In article <g0hrq3$rfb$1 at solaris.cc.vt.edu>, brad <byte8bits at gmail.com> 
wrote:

> I have some c++ binaries that do rather intense number computations. 
> They do it well and rather quickly compared to other languages (not just 
> Python). ...
> 
> However, other components can be written in a more user friendly, more 
> easily maintained language. We've chosen Python for this. The main 
> question now is how to pass the computationally heavy info to c++ from 
> within Pyhton. os.system is not ideal. Just wondering how other folks do 
> this? I have source to some of the c++ code, but some of it is in binary 
> from only. It can take stdin or arguments.

You say you have "binary only", but I hope you have the header files as 
well. If so I would try SWIG first since it is mature and handles C++ 
quite well. If you don't have headers then I have no idea if it's even 
possible.

(For plain C I would start with ctypes, but that doesn't cover this 
case. There are many other options including boost and Pyrex, but I've 
not used those.)

-- Russell



More information about the Python-list mailing list