cf.pickle

cf.pickle(x, filename, overwrite=False)[source]

Write a binary pickled representation of an object to a file.

Note that Field and FieldList objects are picklable and their pickle file size will be very small if their data arrays contain file pointers as opposed to numpy arrays.

The pickling is equivalent to:

import cPickle
fh = open('file.pkl', 'wb')
cPickle.dump(x, fh, 2)
fh.close()

See also

cf.unpickle

Parameters:
x :

The object to be pickled.

filename : str

The name of the file in which to write the pickled representation of x.

overwrite : bool, optional

If True a pre-existing output file is over written. By default an exception is raised if the output file pre-exists.

Returns:

None

Raises:
IOError :

If overwrite is False and the output file pre-exists.

PickleError :

If the object is not picklable.

Examples:

For any picklable object, x:

>>> cf.pickle(x, 'file.pkl')
>>> y = cf.unpickle('file.pkl')
>>> cf.equals(x, y)
True