diff options
Diffstat (limited to 'dyn_module.py')
-rw-r--r-- | dyn_module.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/dyn_module.py b/dyn_module.py new file mode 100644 index 0000000..e12d744 --- /dev/null +++ b/dyn_module.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python +import md5 +import os.path +import imp +import traceback +import sys + +def load_module(code_path): + try: + try: + code_dir = os.path.dirname(code_path) + code_file = os.path.basename(code_path) + + fin = open(code_path, 'rb') + + return imp.load_source(md5.new(code_path).hexdigest(), code_path, fin) + finally: + try: fin.close() + except: pass + except ImportError, x: + traceback.print_exc(file = sys.stderr) + raise + except: + traceback.print_exc(file = sys.stderr) + raise + |