saveobj(filename=None, obj=None, compresslevel=5, verbose=0, folder=None, method='pickle', die=True, *args, **kwargs)[source]

Save an object to file as a gzipped pickle – use compression 5 by default, since more is much slower but not much smaller. Once saved, can be loaded with sc.loadobj(). Note that saveobj()/save() are identical.

  • filename (str or Path) – the filename to save to; if str, passed to sc.makefilepath()

  • obj (literally anything) – the object to save

  • compresslevel (int) – the level of gzip compression

  • verbose (int) – detail to print

  • folder (str) – passed to sc.makefilepath()

  • method (str) – whether to use pickle (default) or dill

  • die (bool) – whether to fail if no object is provided

  • args (list) – passed to pickle.dumps()

  • kwargs (dict) – passed to pickle.dumps()


myobj = ['this', 'is', 'a', 'weird', {'object':44}]
sc.saveobj('myfile.obj', myobj)
sc.saveobj('myfile.obj', myobj, method='dill') # Use dill instead, to save custom classes as well
New in version 1.1.1: removed Python 2 support.
New in version 1.2.2: automatic swapping of arguments if order is incorrect; correct passing of arguments