inc_util.py 549 B

12345678910111213
  1. import sys
  2. def load_module_from_file(module_name, module_path):
  3. if sys.version_info[0] == 3 and sys.version_info[1] >= 5:
  4. import importlib.util
  5. spec = importlib.util.spec_from_file_location(module_name, module_path)
  6. module = importlib.util.module_from_spec(spec)
  7. spec.loader.exec_module(module)
  8. elif sys.version_info[0] == 3 and sys.version_info[1] < 5:
  9. import importlib.machinery
  10. loader = importlib.machinery.SourceFileLoader(module_name, module_path)
  11. module = loader.load_module()
  12. return module