loadarchive#
- loadarchive(filename, folder=None, loadobj=True, loadmetadata=False, remapping=None, die=True, **kwargs)[source]#
Load a zip file saved with
sc.savearchive()
.Note: 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
- Parameters:
filename (str/path) – the file load to (usually ends in .zip)
folder (str) – optional additional folder to load from
loadobj (bool) – whether to load the saved object
loadmetadata (bool) – whether to load the metadata as well
remapping (dict) – any known module remappings between the saved pickle version and the current libraries
die (bool) – whether to fail if an exception is raised (else, just return the metadata)
- Returns:
If loadobj=True and loadmetadata=False, return the object; If loadobj=False and loadmetadata=True, return the metadata If loadobj=True and loadmetadata=True, return a dictionary of both
Example:
obj = MyClass() # Create an arbitrary object sc.savearchive('my-class.zip', obj) # Much later... data = sc.loadarchive('my-class.zip', loadmetadata=True) metadata, obj = data['metadata'], data['obj']
Note: This function expects the zip file to contain two files in it, one called “metadata.json” and one called “sciris_pickle.obj”. If you need to change these, you can manually modify
sc.sc_versioning._metadata_filename
andsc.sc_versioning._obj_filename
, respectively. However, you almost certainly should not do so!New in version 3.0.0.