[C++-sig] How to access a custom module from embedded Python?
Pierre Barbier de Reuille
pierre.barbier at cirad.fr
Tue Apr 13 15:28:16 CEST 2004
Hello !
I had the same problem and found that if you call :
PyImport_AppendInittab(mname, initmodule);
before the Py_Initialize(), with mname your module name and initmodule
the initialisation function, it just works fine.
Pierre
On Sat, 2004-04-10 at 13:35, Peter wrote:
> 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
>
>
> _______________________________________________
> C++-sig mailing list
> C++-sig at python.org
> http://mail.python.org/mailman/listinfo/c++-sig
--
Pierre Barbier de Reuille
INRA - UMR Cirad/Inra/Cnrs/Univ.MontpellierII AMAP
Botanique et Bio-informatique de l'Architecture des Plantes
TA40/PSII, Boulevard de la Lironde
34398 MONTPELLIER CEDEX 5, France
tel : (33) 4 67 61 65 77 fax : (33) 4 67 61 56 68
More information about the Cplusplus-sig
mailing list