Last active
December 28, 2015 14:49
-
-
Save justinfay/7517584 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 importlib | |
IMPORT_CACHE = {} | |
def cache_import(path): | |
"""Import an object from a specified `path`.""" | |
mod, imp = path.rsplit('.', 1) | |
if mod in IMPORT_CACHE: | |
return getattr(IMPORT_CACHE[mod], imp) | |
mod_ = importlib.import_module(mod) | |
IMPORT_CACHE[mod] = mod_ | |
return cache_import(path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment