使用BOOST在程序中嵌入PYTHON代码
#include
using namespace boost::python;
int main()
{
Py_Initialize();
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()) );
Py_Finalize();
}
博客介绍了使用BOOST在程序中嵌入Python代码的方法。给出了具体代码示例,包括初始化Python、导入主模块、获取命名空间,以及执行Python代码来创建文件并写入内容,最后结束Python环境。
1713

被折叠的 条评论
为什么被折叠?



