MCPcopy
hub / github.com/QData/TextAttack / load_module_from_file

Function load_module_from_file

textattack/shared/utils/importing.py:53–64  ·  view source on GitHub ↗

Uses ``importlib`` to dynamically open a file and load an object from it.

(file_path)

Source from the content-addressed store, hash-verified

51
52
53def load_module_from_file(file_path):
54 """Uses ``importlib`` to dynamically open a file and load an object from
55 it."""
56 temp_module_name = f"temp_{time.time()}"
57 colored_file_path = textattack.shared.utils.color_text(
58 file_path, color="blue", method="ansi"
59 )
60 logger.info(f"Loading module from `{colored_file_path}`.")
61 spec = importlib.util.spec_from_file_location(temp_module_name, file_path)
62 module = importlib.util.module_from_spec(spec)
63 spec.loader.exec_module(module)
64 return module

Callers 3

Calls

no outgoing calls

Tested by

no test coverage detected