Importing a String as a Module
Alex Martelli
aleaxit at yahoo.com
Sun Sep 19 14:31:49 EDT 2004
bmatt <bsmatt at gmail.com> wrote:
> Hello All,
>
> I would like to import an internal string as a module into the python
> interpreter. Unfortunately it looks like all of the PyImport functions
> only take a module name and load the module from the .py file. Is
> there a way to import a module from a string (similar to the way the
> PyRun_String function works)? I have tried to use the PyRun_String
> function and then use PyImport_AddModule but it doesn't look like the
> things defined in the string are in the module dictionary.
Make an empty module first (PyImport_AddModule shd be OK), get its
dictionary, run the string with that dictionary as its globals and
locals.
Alex
More information about the Python-list
mailing list