/usr/share/pyshared/dipy/io/pickles.py is in python-dipy 0.5.0-3.
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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | import cPickle
def save_pickle(fname,dix):
''' Save `dix` to `fname` as pickle
Parameters
------------
fname : str
filename to save object e.g. a dictionary
dix : str
dictionary or other object
Examples
----------
>>> import os
>>> from tempfile import mkstemp
>>> fd, fname = mkstemp() # make temporary file (opened, attached to fh)
>>> d={0:{'d':1}}
>>> save_pickle(fname, d)
>>> d2=load_pickle(fname)
We remove the temporary file we created for neatness
>>> os.close(fd) # the file is still open, we need to close the fh
>>> os.remove(fname)
See also
----------
dipy.io.pickles.load_pickle
'''
out=open(fname,'wb')
cPickle.dump(dix,out)
out.close()
def load_pickle(fname):
''' Load object from pickle file `fname`
Parameters
------------
fname : str
filename to load dict or other python object
Returns
---------
dix : object
dictionary or other object
Examples
----------
dipy.io.pickles.save_pickle
'''
inp=open(fname,'rb')
dix=cPickle.load(inp)
inp.close()
return dix
|