/usr/share/pyshared/statsmodels/iolib/smpickle.py is in python-statsmodels 0.4.2-1.2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | '''Helper files for pickling'''
def _get_file_obj(fname, mode):
"""
Light wrapper to handle strings and let files (anything else) pass through
"""
try:
fh = open(fname, mode)
except (IOError, TypeError):
fh = fname
return fh
def save_pickle(obj, fname):
"""
Save the object to file via pickling.
Parameters
----------
fname : str
Filename to pickle to
"""
import cPickle as pickle
fout = _get_file_obj(fname, 'wb')
pickle.dump(obj, fout, protocol=-1)
def load_pickle(fname):
"""
Load a previously saved object from file
Parameters
----------
fname : str
Filename to unpickle
Notes
-----
This method can be used to load *both* models and results.
"""
import cPickle as pickle
fin = _get_file_obj(fname, 'rb')
return pickle.load(fin)
|