🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Calling Python function from C using BOOST

Started by
-1 comments, last by stodge 20 years, 5 months ago
I read in the BOOST documentation that you can use the following to execute arbitrary Python code from within a C/C++ application: 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
---------------------http://www.stodge.net

This topic is closed to new replies.

Advertisement