Hacking the scope to pieces

Hugh Macdonald hugh.macdonald at gmail.com
Tue May 24 12:33:24 EDT 2005


Maybe I misunderstood what you meant, but I couldn't quite manage to
get this one working....

My initial hopes about __import__() were that I could define it inside
my new module (moduleLoader) and, when the module is imported, it could
do stuff (like try to hold onto the vars() and globals() from the
importing scope). However, I couldn't get it to import...

The route I've ended up going (which is just about as simple) is just
to return the new module from moduleLoader.loadModule, so my loading
code is:

import moduleLoader
myModule = moduleLoader.loadModule("myModule",
os.getenv("MODULE_VERSION"))

I've also switched over to using 'inp' for this, rather than creating a
compiler string - much nicer....

Anyway, thanks Skip

--
Hugh




More information about the Python-list mailing list