Unlocked

Untitled

Sep 11th, 2016
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.57 KB | None | 0 0
  1. import os
  2. import imp
  3. import inspect
  4.  
  5. obj_list = []
  6.  
  7. dir_path = os.path.dirname(os.path.realpath(__file__))
  8. pattern = "*.py"
  9.  
  10. for path, subdirs, files in os.walk(dir_path):
  11.     for name in files:
  12.         if fnmatch(name, pattern):
  13.             found_module = imp.find_module(name[:-3], [path])
  14.             module = imp.load_module(name, found_module[0], found_module[1], found_module[2])
  15.             for mem_name, obj in inspect.getmembers(module):
  16.                 if inspect.isclass(obj) and inspect.getmodule(obj) is module:
  17.                     obj_list.append(obj())
Advertisement
Add Comment
Please, Sign In to add comment