fnunpickle

astropy.io.misc.pickle_helpers.fnunpickle(fileorname, number=0, usecPickle=True) [edit on github][source]

Unpickle pickled objects from a specified file and return the contents.

Parameters :

fileorname : str or file-like

The file name or file from which to unpickle objects. If a file object, it should have been opened in binary mode.

number : int

If 0, a single object will be returned (the first in the file). If >0, this specifies the number of objects to be unpickled, and a list will be returned with exactly that many objects. If <0, all objects in the file will be unpickled and returned as a list.

usecPickle : bool

If True, the cPickle module is to be used in place of pickle (cPickle is faster). This only applies for python 2.x.

Returns :

contents : obj or list

If number is 0, this is a individual object - the first one unpickled from the file. Otherwise, it is a list of objects unpickled from the file.

Raises :

EOFError :

If number is >0 and there are fewer than number objects in the pickled file.

Page Contents