dlpt.importer module
Dynamically import python module in the runtime.
- class dlpt.importer.ModuleImporter(file_path: str, base_dir_path: str | None = None)
Bases:
object
- __init__(file_path: str, base_dir_path: str | None = None)
Dynamically import module from a given
file_path
.- Parameters:
file_path – abs path to a python module (file) which will be dynamically imported.
base_dir_path – path to a root directory from where module will be imported. If not specified,
file_path
root directory is used asbase_dir_path
. Example:file_path = C:/root/someDir/someSubdir/myModule.py
base_dir_path = C:/root/someDir/
-> module will be imported as: someSubdir.myModule
Note
base_dir_path
is added to sys.path. It is NOT removed once object is garbage-collected.
- get_module() module
- Returns:
Imported module instance (object).
- has_object(name: str, raise_exception: bool = True) bool
Check if imported module has object with
name
.- Parameters:
name – name of the object to check existence in imported module.
raise_exception – if True, exception is raised if object is not found. Otherwise, bool is returned (True if object is found, False otherwise).
- Returns:
True if imported module has object with name, False otherwise.