the following functions are used to turn an object into byte-stream dump(objectfile [protocol ]dumps pickled representation of object to the file object file protocol specifies the output format of the data protocol (the defaultis text-based format that is backwards-compatible with earlier versions of python protocol is binary protocol that is also compatible with most earlier python versions protocol is newer protocol that provides more efficient pickling of classes and instances protocol is used by python and is not backwards-compatible if protocol is negativethe most modern protocol will be selected the variable pickle highest_protocol contains the highest protocol available if object doesn' support picklinga pickle picklingerror exception is raised dumps(object [protocol]same as dump()but returns string containing the pickled data the following example shows how you use these functions to save objects to filef open('myfile''wb'pickle dump(xfpickle dump(yfdump more objects close(the following functions are used to restore pickled object load(fileloads and returns pickled representation of an object from the file object file it is not necessary to specify the input protocol as it is automatically detected pickle unpicklingerror exception is raised if the file contains corrupted data that can' be decoded if an end-of-file is detectedan eoferror exception is raised loads(stringsame as load()but reads the pickled representation of an object from string the following example shows how you use these functions to load dataf open('myfile''rb' pickle load(fy pickle load(fload more objects close(when loadingit is not necessary to specify the protocol or any information about the type of object being loaded that information is saved as part of the pickle data format itself if you are pickling more than one python objectyou can simply make repeated calls to dump(and load(as shown in the previous examples when making multiple callsyou simply have to make sure the sequence of load(calls matches the sequence of dump(calls that were used to write the file when working with complicated data structures involving cycles or shared referencesusing dump(and load(can be problematic because they don' maintain any internal state about objects that have already been pickled or restored this can result in output files that are excessively large and that don' properly restore the relationship lib fl ff