Skip to content

Instantly share code, notes, and snippets.

@KitB
Last active December 21, 2015 10:49
Show Gist options
  • Save KitB/6294508 to your computer and use it in GitHub Desktop.
Save KitB/6294508 to your computer and use it in GitHub Desktop.
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))
@KitB
Copy link
Author

KitB commented Aug 21, 2013

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).

@KitB
Copy link
Author

KitB commented Aug 21, 2013

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