load#

class load(filename=None, folder=None, verbose=False, die=None, remapping=None, method='pickle', auto_remap=True, **kwargs)[source]#

Load a file that has been saved as a gzipped pickle file, e.g. by sc.save(). Accepts either a filename (standard usage) or a file object as the first argument. Note that sc.load()/sc.loadobj() are aliases of each other.

Note 1: Since this function relies on pickle, it can potentially execute arbitrary code, so you should only use it with sources you trust. For more information, see: https://docs.python.org/3/library/pickle.html

Note 2: When a pickle file is loaded, Python imports any modules that are referenced in it. This is a problem if module has been renamed. In this case, you can use the remapping argument to point to the new modules or classes. For more robustness, use the sc.savearchive()/sc.loadarchive() functions.

Parameters:
  • filename (str/Path) – the filename (or full path) to load

  • folder (str/Path) – the folder

  • verbose (bool) – print details

  • die (bool) – whether to raise an exception if errors are encountered (otherwise, load as much as possible)

  • remapping (dict) – way of mapping old/unavailable module names to new

  • method (str) – method for loading (usually pickle or dill)

  • auto_remap (bool) – whether to use known deprecations to load failed pickles

  • kwargs (dict) – passed to pickle.loads()/dill.loads()

Examples:

obj = sc.load('myfile.obj') # Standard usage
old = sc.load('my-old-file.obj', method='dill', ignore=True) # Load classes from saved files
old = sc.load('my-old-file.obj', remapping={'foo.Bar':cat.Mat}) # If loading a saved object containing a reference to foo.Bar that is now cat.Mat
old = sc.load('my-old-file.obj', remapping={'foo.Bar':('cat', 'Mat')}) # Equivalent to the above
New in version 1.1.0: “remapping” argument
New in version 1.2.2: ability to load non-gzipped pickles; support for dill; arguments passed to loader