Created
August 6, 2012 21:58
-
-
Save tebeka/3278829 to your computer and use it in GitHub Desktop.
find module by name
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 sys | |
import imp | |
def find_module(name): | |
names = name.split('.') | |
path = sys.path | |
while names: | |
name = names.pop(0) | |
file, pathname, desc = imp.find_module(name) | |
module = imp.load_module(name, file, pathname, desc) | |
path = getattr(module, '__path__', None) | |
return module |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment