Skip to content

Instantly share code, notes, and snippets.

@pbdeuchler
Created June 22, 2011 20:33
Show Gist options
  • Save pbdeuchler/1041093 to your computer and use it in GitHub Desktop.
Save pbdeuchler/1041093 to your computer and use it in GitHub Desktop.
Trying to dynamically import modules/call methods within said modules
#import
pathname = os.path.dirname(sys.argv[0]) + "/"
pathname = pathname + "/modules/"
__modules__ = [ os.path.basename(f)[:-3] for f in glob.glob(os.path.dirname(pathname)+"/*.py")]
for module in __modules__:
__import__(module)
#calling checkMe()
for module in __modules__:
m = sys.modules[__name__][module]
getattr(m, 'checkMe').__call__()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment