Say there is a folder, \'/home/user/temp/a40bd22344\'. The name is completely random and changes in every iteration. I need to be able to import this folder in Python using
You first import it with import:
>>> __import__('temp/a40bd22344')
Then you make sure that this module gets known to Python as project
:
>>> import sys
>>> sys.modules['project'] = sys.modules.pop('temp/a40bd22344')
After this, anything importing project in the current Python session will get the original module
>>> import project
>>> project
This will work also for sub-modules: if you have a foobar.py in the same location you'll get
>>> import project.foobar
>>> project.foobar
Addendum. Here's what I'm running:
>>> print sys.version
2.5.2 (r252:60911, Jul 31 2008, 17:28:52)
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)]