fipy.tools.dump¶
Functions
|
Read a pickled object from a file. |
|
Pickle an object and write it to a file. |
- fipy.tools.dump.read(filename, fileobject=None, communicator=DummyComm(), mesh_unmangle=False)¶
Read a pickled object from a file. Returns the unpickled object. Wrapper for cPickle.load().
- Parameters:
filename (str) – Name of the file to unpickle the object from. If the filename extension is .gz, the file is first decompressed.
fileobject (file) – Used to remove temporary files
communicator (CommWrapper) – A duck-typed object with procID and Nproc attributes is sufficient
mesh_unmangle (bool) – Whether to correct improper pickling of non-uniform meshes (ticket:243)
- fipy.tools.dump.write(data, filename=None, extension='', communicator=DummyComm())¶
Pickle an object and write it to a file. Wrapper for cPickle.dump().
Test to check pickling and unpickling.
>>> from fipy.meshes import Grid1D >>> old = Grid1D(nx = 2) >>> f, tempfile = write(old) >>> new = read(tempfile, f) >>> print(old.numberOfCells == new.numberOfCells) True
- Parameters:
data – Object to be pickled.
filename (str) – Name of the file to place the pickled object. If filename is None then a temporary file will be used and the file object and file name will be returned as a tuple. If the filename ends in .gz, the file is automatically saved in compressed gzip format.
extension (str) – File extension to append if filename is not given. If set to .gz, the file is automatically saved in compressed gzip format.
communicator (CommWrapper) – A duck-typed object with procID and Nproc attributes is sufficient