Boost learning

zhaozj2021-02-16  52

Use Boost to embed Python code in the program

#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 ();

}

转载请注明原文地址:https://www.9cbs.com/read-18334.html

New Post(0)