python embedded in C program, how to import?

Rainer Deyke root at rainerdeyke.com
Tue Apr 17 10:04:38 EDT 2001


"Harald Kirsch" <kirschh at lionbioscience.com> wrote in message
news:yv2y9szzwkm.fsf at lionsp093.lion-ag.de...
>
>
> I tried this (PYCHECK does some error checking):
>
>     PyObject *pymodMain;
>     PyObject *pymodRe;
>     Py_Initialize();
>     pymodMain = PyImport_ImportModule("__main__");
>     globals = PyModule_GetDict(pymodMain);
>     locals = PyDict_New();
>     PyRun_String("import re", Py_file_input, globals, locals);
>     PYCHECK;
>
> Then I run:
>     PyRun_String("print globals()", Py_file_input, globals, locals);
>
> and get:
>
> {'__doc__': None, '__name__': '__main__', '__builtins__': <module
'__builtin__' (built-in)>}
>
> You see that 're' is not in globals. Why? How do I have to import re
> such that it is available for example to string I run with
> PyRun_String?

It's in 'locals'.


--
Rainer Deyke (root at rainerdeyke.com)
Shareware computer games           -           http://rainerdeyke.com
"In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor





More information about the Python-list mailing list