Created
July 30, 2010 15:24
-
-
Save pelletier/500708 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
def load_modules(path): | |
""" | |
Load all Python modules from a directory into a dict. | |
:param path: the path to the living place of the modules to load. | |
:type path: :class:`str` | |
:returns: map between loaded modules name and their content. | |
:rtype: :class:`dict` | |
""" | |
import os, imp | |
dir_list = os.listdir(path) | |
mods = {} | |
for fname in dir_list: | |
name, ext = os.path.splitext(fname) | |
if ext == '.py' and not name == '__init__': | |
f, filename, descr = imp.find_module(name, [path]) | |
mods[name] = imp.load_module(name, f, filename, descr) | |
return mods |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment