Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

12345678910111213141516171819202122232425262728293031
  1. import sys
  2. class temporary_python_path(object):
  3. """
  4. Acts as a context manager to temporarily prepend a list of paths to
  5. sys.path
  6. """
  7. def __init__(self, paths):
  8. self.paths = paths
  9. self.original_paths = sys.path[:]
  10. def __enter__(self):
  11. sys.path = self.paths + self.original_paths
  12. def __exit__(self, exc_type, exc_value, traceback):
  13. sys.path = self.original_paths
  14. def delete_from_import_cache(module_name):
  15. """
  16. Deletes imported modules from the cache, so that they do not interfere with
  17. subsequent imports of different modules of the same names.
  18. Useful in situations where dynamically-created files are imported.
  19. """
  20. parts = module_name.split(".")
  21. for i, _ in enumerate(parts, 1):
  22. submodule_name = ".".join(parts[:i])
  23. del sys.modules[submodule_name]