Last active
December 21, 2015 10:49
-
-
Save KitB/6294508 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import imp | |
def get_module(name): | |
(file, p, desc) = imp.find_module(name) | |
m = imp.new_module(name) | |
exec file in m.__dict__ | |
return m | |
_n_reloads = 0 | |
def old_get_module(name): | |
_n_reloads += 1 | |
suffix = "_reloaded_%d_times" % self._n_reloads | |
# Yes, we're polluting sys.modules with '..._reloaded_n_times' modules | |
return imp.load_module(name + suffix, *imp.find_module(name)) |
Now we're basically getting into reimplementing the import mechanism :/
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Idea: hook into exec'd file's import mechanism using the
__dict__
? To prevent the file from pulling in new modules (make them import using this).