compiling module from string and put into namespace
tbrkic at yahoo.com
Sat May 13 20:45:32 CEST 2006
> I dont want the caller to call import but a function.
>>> type (__builtins__.__import__)
I didnt mean that __import__ isnt a function, but that I want to
make a function called ImoprtFile that actually does something
very similar that what __import__.
So to rephrsase the questin how does __import__ load a module
into the callers namespace.
parsedCode = Parser(fileName).Parse()
module = new.module(name)
exec parsedCode in module.__dict__
sys.modules[name] = module
import name #!!!!!!! This doesn't work. Imports in file1
fileName.function() #This wont work because the import happened
locally in file1!!!!!!!!!!!!!
Now the import in file1 doesnt take effect in file2. So what do I have
do to make that work. And I dont want to do a custom hook to import.
So how does __import__ do?
More information about the Python-list