pyppin.base.import_file

[View Source]

A function to import a Python file from its pathname.

Functions

import_file(filename[, name, reimport])

Import a single Python file.

pyppin.base.import_file.import_file(filename: Union[str, Path], name: Optional[str] = None, reimport: bool = False) module[source]

Import a single Python file.

Unlike the methods in importlib, this takes an honest-to-Cthulhu pathname as its argument.

WARNING: This will actually exec the file in question, just like importing it would. Do not call this on untrusted data for hopefully obvious reasons.

Parameters
  • filename – The file to import.

  • name – The name of the module to create. If not given, this will default to the name of the file.

  • reimport – If the name is already imported, and this is true, we’ll try to reimport it. That said, this is a fragile operation, because any symbols being actively referenced from the already-imported file are going to still be there; that is, it has all the same caveats as importlib.reload.

Returns: The newly-imported module.