MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / convert_path_to_module

Function convert_path_to_module

scripts/validate_solutions.py:30–35  ·  view source on GitHub ↗

Converts a file path to a Python module

(file_path: pathlib.Path)

Source from the content-addressed store, hash-verified

28
29
30def convert_path_to_module(file_path: pathlib.Path) -> ModuleType:
31 """Converts a file path to a Python module"""
32 spec = importlib.util.spec_from_file_location(file_path.name, str(file_path))
33 module = importlib.util.module_from_spec(spec) # type: ignore[arg-type]
34 spec.loader.exec_module(module) # type: ignore[union-attr]
35 return module
36
37
38def all_solution_file_paths() -> list[pathlib.Path]:

Callers 1

test_project_eulerFunction · 0.85

Calls

no outgoing calls

Tested by 1

test_project_eulerFunction · 0.68