Pass data from Python to C++

brad byte8bits at gmail.com
Thu May 15 13:27:11 EDT 2008


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). An example:

> brad at qu:~/$ date && ./compute.cpp.o < 1_million.txt > /dev/null && date
> Thu May 15 13:08:28 EDT 2008
> Thu May 15 13:08:31 EDT 2008
> brad at qu:~/$ date && python compute.py < 1_million.txt > /dev/null && date
> Thu May 15 13:08:38 EDT 2008
> Thu May 15 13:14:50 EDT 2008

In this case, c++ does one million things in 3 seconds that Python takes 
more than 6 minutes to do. The one million is a minimum. At times the 
computations are in the billions. This is why c++ was chosen.

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.

Thanks for any tips,

Brad




More information about the Python-list mailing list