Skip to content

Instantly share code, notes, and snippets.

@borntyping
Created March 19, 2011 20:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save borntyping/877775 to your computer and use it in GitHub Desktop.
Save borntyping/877775 to your computer and use it in GitHub Desktop.
Command importer
import os, sys
commandlist = {}
for module in os.listdir(os.path.dirname(__file__)):
if module == '__init__.py' or module[-3:] != '.py':
continue
__import__(module[:-3], locals(), globals())
name = 'tools.'+module[:-3]
print "Importing "+name+"..."
try:
commands = getattr(sys.modules[name], 'commands')
for key in commands.keys():
if key in commandlist: continue
commandlist[key] = commands[key]
except AttributeError:
continue
print commandlist
del module, os, sys
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment