Creating "virtual" module-namespace

Harald ghum.19.ghum at spamgourmet.com
Thu Dec 12 11:14:39 EST 2002


Nicodemus <nicodemus at globalite.com.br> wrote in message news:<mailman.1039692015.21955.python-list at python.org>...

> If I understood correctly, you have for example ['ftplib', 'mymodule']
> stored in a database, and you want to, given one of the modules of the
> database, use them like this:
Not exactly. I have not stored the complete code of modules in a
database. I retrieve them to a string. And I want to treat (the
content of) this string like a module.

I CAN allready use the content of this string via compile and exec.
BUT all the modules are in the same namespace.

> mymodule = __import__('mymodule')
If I try to do this on my string...
that is
mymodule=__import__(a)

where a contains the usual...
a='class nasenbaer:\n   def singe(self):\n      print "gugug"\n\n'


it yields an
ImportError: No module named class nasenbaer:

Thanks for your considerations,

Harald



More information about the Python-list mailing list