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 folder
old = sc.importbypath('/path/to/old/lib', name='oldlib')
new = sc.importbypath('/path/to/new/lib', name='newlib')

See also sc.importbyname().

New in version 3.0.0.