import_python_source_file#

import_python_source_file(fname)[source]#

Import a Python source file and return the loaded module.

See the original StackOverflow answer.

Parameters:

fname (Path) – The full path to the source file. It may container characters like . or -.

Returns:

The imported module

Raise:
ImportError: If the file cannot be imported (e.g, if it’s not a .py file or if

it does not exist).

Exception: Any exception that is raised while executing the module (e.g.,

:exc:`SyntaxError). These are errors made by the author of the module!

Return type:

module