# This is the modified function to print out all the import statements that are generated # on the fly by the module. def importAll(path, globals, locals, excludes=()): """Given a list of modules, import all names from each module into the global namespace.""" mods = importModules(path, globals, locals, excludes) for mod in mods.values(): if hasattr(mod, '__all__'): names = mod.__all__ else: names = [n for n in dir(mod) if n[0] != '_'] for k in names: if hasattr(mod, k): pkg_dir, mod_file = os.path.split(mod.__file__) mod_name, ext = os.path.splitext(mod_file) rel_pkg = os.path.relpath(pkg_dir, os.path.dirname(__file__)) pkg_import = rel_pkg.replace(os.path.sep, '.') if mod_name == '__init__': mod_import = 'from ' + '.' + pkg_import else: mod_import = 'from ' + '.' + pkg_import + '.' + mod_name print mod_import, 'import', k globals[k] = getattr(mod, k)