Skip to content

importlib

experiment.importlib

get_module_from_path

get_module_from_path(file_path: str) -> ModuleType

입력으로 받은 파이썬 파일을 모듈화하여 반환합니다.

Parameters:

  • file_path (str) –

    path to python file

Returns:

  • ModuleType ( ModuleType ) –

    loaded module

Source code in ResearchToolkit/experiment/importlib.py
def get_module_from_path(file_path: str) -> ModuleType:
    """입력으로 받은 파이썬 파일을 모듈화하여 반환합니다.

    Args:
        file_path (str): path to python file

    Returns:
        ModuleType: loaded module
    """
    module_name = os.path.basename(file_path).rstrip(".py")
    spec = importlib.util.spec_from_file_location(module_name, file_path)
    module = importlib.util.module_from_spec(spec)
    spec.loader.exec_module(module)

    return module