python embedded in C program, how to import?
Harald Kirsch
kirschh at lionbioscience.com
Tue Apr 17 05:48:09 EDT 2001
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?
Harald Kirsch
--
----------------+------------------------------------------------------
Harald Kirsch | kirschh at lionbioscience.com | "How old is the epsilon?"
LION bioscience | +49 6221 4038 172 | -- Paul Erdös
More information about the Python-list
mailing list