[C++-sig] How to access a custom module from embedded Python?

Peter python at cityofdreams.com
Sat Apr 10 13:35:25 CEST 2004


I've just started using boost.python and have embedded a Python
interpretor in a test app.  But how do I access a Python extension I
have created in the same app that embeds Python?

e.g. I define a hello module

 BOOST_PYTHON_MODULE(hello)
 {
     def("greet", greet);
 }

and in the same code I embed Python:

 Py_Initialize();

 handle<> main_module(borrowed( 
          PyImport_AddModule("__main__") ));
 dict main_namespace(handle<>(borrowed( 
          PyModule_GetDict(main_module.get()) )));

And am stuck at the next step... how do I call hello.greet() from this
embedded Python instance?

Thanks,
Peter





More information about the Cplusplus-sig mailing list