handle<> main_module(borrowed( PyImport_AddModule("__main__") ));
handle<> main_namespace(borrowed( PyModule_GetDict(main_module.get()) ));
handle<>( PyRun_String("hello = file(''hello.txt'', ''w'')\n"
"hello.write(''Hello world!'')\n"
"hello.close()", Py_file_input,
main_namespace.get(), main_namespace.get()) );
One thing I would need to do in my project, if I used Python and BOOST, would be to invoke Python functions from within the C++ application.
Would the above solution be a good one, using say Py_single_input instead of Py_file_input, or is there a better method that you would recommend?
Thanks
Calling Python function from C using BOOST
I read in the BOOST documentation that you can use the following to execute arbitrary Python code from within a C/C++ application:
---------------------http://www.stodge.net
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement