Skip to content

Instantly share code, notes, and snippets.

@theneosloth
Last active September 13, 2015 21:06
Show Gist options
  • Save theneosloth/ec00ebb7a075f8fa0c03 to your computer and use it in GitHub Desktop.
Save theneosloth/ec00ebb7a075f8fa0c03 to your computer and use it in GitHub Desktop.
Import all methods from the files in a given directory.
import glob
import imp
from os.path import join, basename, splitext
def importModules(dir):
modules = []
methods = []
for path in glob.glob(join(dir, '[!_]*.py')):
name, ext = splitext(basename(path))
modules.append(imp.load_source(name, path))
for module in modules:
methods += [f for _, f in module.__dict__.iteritems() if callable(f)]
return methods
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment