importbypath#
- importbypath(path, name=None)[source]#
Import a module by path.
Useful for importing multiple versions of the same module for comparison purposes.
- Parameters:
path (str/path) – the path to load the module from (with or without __init__.py)
name (str) – the name of the loaded module (by default, the file or folder name from the path)
Examples:
# Load a module that isn't importable otherwise mymod = sc.importbypath('my file with spaces.py') # Load two versions of the same module old = sc.importbypath('/path/to/old/mylib') new = sc.importbypath('/path/to/new/mylib') assert new.__version__ > old.__version__ # Example version comparison (see also sc.compareverisons())
See also
sc.importbyname()
.New in version 3.0.0.New in version 3.2.0: Allow importing two modules that have self imports (e.g. “import mylib” from within mylib)