Reputation: 906
What I am trying to do is that I want to read a file using python, and then 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!
Upvotes: 3
Views: 5723
Reputation: 88711
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.
Upvotes: 1
Reputation: 8614
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
Upvotes: 7
Reputation: 12651
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.
Upvotes: 2