Importing a String as a Module

B

bmatt

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.

Thanks
 
A

Alex Martelli

bmatt said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,206
Messages
2,571,069
Members
47,678
Latest member
Aniruddha Das

Latest Threads

Top