开发者

connecting c/c++ and python

What I am trying to do is that I want to read a file using python, and th开发者_运维问答en with the data in the file, create a variable in c/c++(I don't want to read var from the file :) ).

Is this possible? If this is possible, then how would you do it?

Thank you guys!


Maybe Boost.Python can help.

You could expose a C++ function to your Python script. Something like that:

void do_sth_with_processed_data(const std::string& data)
{
  // …
}

BOOST_PYTHON_MODULE(do_sth)
{
  def("do_sth_with_processed_data", do_sth_with_processed_data);
}

In your Python script you now could have:

import do_sth

// … 

do_sth_with_processed_data(my_processed_data) // this calls the c++ function


Yes. Open the first file in Python, process it and save the results to a second file.

Then open the second file in your C or C++ program and use the data.


Swig can generate a Python interface to C or C++ code for you automatically. Since it wraps constructors you could read the data in Python and then pass it (with a little care) to the constructor of a C++ class for example.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜