blob: ebc897558d98a9c6d2939a630ada7ce72423b3b7 [file] [log] [blame]
Fred Drake295da241998-08-10 19:42:37 +00001\section{\module{pickle} ---
Fred Drakeffbe6871999-04-22 21:23:22 +00002 Python object serialization}
Fred Drakeb91e9341998-07-23 17:59:49 +00003
Fred Drakeffbe6871999-04-22 21:23:22 +00004\declaremodule{standard}{pickle}
Fred Drakeb91e9341998-07-23 17:59:49 +00005\modulesynopsis{Convert Python objects to streams of bytes and back.}
Fred Drake38e5d272000-04-03 20:13:55 +00006% Substantial improvements by Jim Kerr <jbkerr@sr.hp.com>.
Fred Drakeb91e9341998-07-23 17:59:49 +00007
Guido van Rossumd1883581995-02-15 15:53:08 +00008\index{persistency}
9\indexii{persistent}{objects}
10\indexii{serializing}{objects}
11\indexii{marshalling}{objects}
12\indexii{flattening}{objects}
13\indexii{pickling}{objects}
14
Guido van Rossum470be141995-03-17 16:07:09 +000015
Fred Drake41796911999-07-02 14:25:37 +000016The \module{pickle} module implements a basic but powerful algorithm
17for ``pickling'' (a.k.a.\ serializing, marshalling or flattening)
18nearly arbitrary Python objects. This is the act of converting
19objects to a stream of bytes (and back: ``unpickling''). This is a
20more primitive notion than persistency --- although \module{pickle}
21reads and writes file objects, it does not handle the issue of naming
22persistent objects, nor the (even more complicated) area of concurrent
23access to persistent objects. The \module{pickle} module can
24transform a complex object into a byte stream and it can transform the
25byte stream into an object with the same internal structure. The most
26obvious thing to do with these byte streams is to write them onto a
27file, but it is also conceivable to send them across a network or
28store them in a database. The module
Fred Drakeffbe6871999-04-22 21:23:22 +000029\refmodule{shelve}\refstmodindex{shelve} provides a simple interface
30to pickle and unpickle objects on DBM-style database files.
31
Guido van Rossumd1883581995-02-15 15:53:08 +000032
Fred Drake9b28fe21998-04-04 06:20:28 +000033\strong{Note:} The \module{pickle} module is rather slow. A
Fred Drakeffbe6871999-04-22 21:23:22 +000034reimplementation of the same algorithm in C, which is up to 1000 times
Fred Drake41796911999-07-02 14:25:37 +000035faster, is available as the
36\refmodule{cPickle}\refbimodindex{cPickle} module. This has the same
37interface except that \class{Pickler} and \class{Unpickler} are
38factory functions, not classes (so they cannot be used as base classes
39for inheritance).
Guido van Rossum736fe5e1997-12-09 20:45:08 +000040
Fred Drake38e5d272000-04-03 20:13:55 +000041Although the \module{pickle} module can use the built-in module
42\refmodule{marshal}\refbimodindex{marshal} internally, it differs from
43\refmodule{marshal} in the way it handles certain kinds of data:
Guido van Rossumd1883581995-02-15 15:53:08 +000044
45\begin{itemize}
46
Fred Drake38e5d272000-04-03 20:13:55 +000047\item Recursive objects (objects containing references to themselves):
48 \module{pickle} keeps track of the objects it has already
49 serialized, so later references to the same object won't be
50 serialized again. (The \refmodule{marshal} module breaks for
51 this.)
Guido van Rossumd1883581995-02-15 15:53:08 +000052
Fred Drake38e5d272000-04-03 20:13:55 +000053\item Object sharing (references to the same object in different
54 places): This is similar to self-referencing objects;
55 \module{pickle} stores the object once, and ensures that all
56 other references point to the master copy. Shared objects
57 remain shared, which can be very important for mutable objects.
Guido van Rossumd1883581995-02-15 15:53:08 +000058
Fred Drake38e5d272000-04-03 20:13:55 +000059\item User-defined classes and their instances: \refmodule{marshal}
60 does not support these at all, but \module{pickle} can save
61 and restore class instances transparently. The class definition
62 must be importable and live in the same module as when the
63 object was stored.
Guido van Rossumd1883581995-02-15 15:53:08 +000064
65\end{itemize}
66
Fred Drake9b28fe21998-04-04 06:20:28 +000067The data format used by \module{pickle} is Python-specific. This has
Guido van Rossumd1883581995-02-15 15:53:08 +000068the advantage that there are no restrictions imposed by external
Fred Drakeffbe6871999-04-22 21:23:22 +000069standards such as
70XDR\index{XDR}\index{External Data Representation} (which can't
71represent pointer sharing); however it means that non-Python programs
72may not be able to reconstruct pickled Python objects.
Guido van Rossumd1883581995-02-15 15:53:08 +000073
Fred Drake9b28fe21998-04-04 06:20:28 +000074By default, the \module{pickle} data format uses a printable \ASCII{}
Guido van Rossum736fe5e1997-12-09 20:45:08 +000075representation. This is slightly more voluminous than a binary
76representation. The big advantage of using printable \ASCII{} (and of
Fred Drake9b28fe21998-04-04 06:20:28 +000077some other characteristics of \module{pickle}'s representation) is that
Guido van Rossum736fe5e1997-12-09 20:45:08 +000078for debugging or recovery purposes it is possible for a human to read
79the pickled file with a standard text editor.
80
81A binary format, which is slightly more efficient, can be chosen by
82specifying a nonzero (true) value for the \var{bin} argument to the
Fred Drake9b28fe21998-04-04 06:20:28 +000083\class{Pickler} constructor or the \function{dump()} and \function{dumps()}
Guido van Rossum736fe5e1997-12-09 20:45:08 +000084functions. The binary format is not the default because of backwards
85compatibility with the Python 1.4 pickle module. In a future version,
86the default may change to binary.
Guido van Rossumd1883581995-02-15 15:53:08 +000087
Fred Drake9b28fe21998-04-04 06:20:28 +000088The \module{pickle} module doesn't handle code objects, which the
Fred Drake41796911999-07-02 14:25:37 +000089\refmodule{marshal}\refbimodindex{marshal} module does. I suppose
90\module{pickle} could, and maybe it should, but there's probably no
91great need for it right now (as long as \refmodule{marshal} continues
92to be used for reading and writing code objects), and at least this
93avoids the possibility of smuggling Trojan horses into a program.
Guido van Rossumd1883581995-02-15 15:53:08 +000094
Fred Drake9b28fe21998-04-04 06:20:28 +000095For the benefit of persistency modules written using \module{pickle}, it
Guido van Rossumd1883581995-02-15 15:53:08 +000096supports the notion of a reference to an object outside the pickled
97data stream. Such objects are referenced by a name, which is an
Guido van Rossum470be141995-03-17 16:07:09 +000098arbitrary string of printable \ASCII{} characters. The resolution of
Fred Drake9b28fe21998-04-04 06:20:28 +000099such names is not defined by the \module{pickle} module --- the
Guido van Rossumd1883581995-02-15 15:53:08 +0000100persistent object module will have to implement a method
Fred Drake9b28fe21998-04-04 06:20:28 +0000101\method{persistent_load()}. To write references to persistent objects,
102the persistent module must define a method \method{persistent_id()} which
Guido van Rossumd1883581995-02-15 15:53:08 +0000103returns either \code{None} or the persistent ID of the object.
104
105There are some restrictions on the pickling of class instances.
106
107First of all, the class must be defined at the top level in a module.
Guido van Rossum736fe5e1997-12-09 20:45:08 +0000108Furthermore, all its instance variables must be picklable.
Guido van Rossumd1883581995-02-15 15:53:08 +0000109
Fred Drake19479911998-02-13 06:58:54 +0000110\setindexsubitem{(pickle protocol)}
Guido van Rossum470be141995-03-17 16:07:09 +0000111
Fred Drake9b28fe21998-04-04 06:20:28 +0000112When a pickled class instance is unpickled, its \method{__init__()} method
Guido van Rossum736fe5e1997-12-09 20:45:08 +0000113is normally \emph{not} invoked. \strong{Note:} This is a deviation
114from previous versions of this module; the change was introduced in
115Python 1.5b2. The reason for the change is that in many cases it is
116desirable to have a constructor that requires arguments; it is a
Fred Drake9b28fe21998-04-04 06:20:28 +0000117(minor) nuisance to have to provide a \method{__getinitargs__()} method.
Guido van Rossum736fe5e1997-12-09 20:45:08 +0000118
Fred Drake9b28fe21998-04-04 06:20:28 +0000119If it is desirable that the \method{__init__()} method be called on
120unpickling, a class can define a method \method{__getinitargs__()},
Fred Drakecf7e8301998-01-09 22:36:51 +0000121which should return a \emph{tuple} containing the arguments to be
Fred Drake9b28fe21998-04-04 06:20:28 +0000122passed to the class constructor (\method{__init__()}). This method is
Guido van Rossum57930391997-12-30 17:44:48 +0000123called at pickle time; the tuple it returns is incorporated in the
124pickle for the instance.
Fred Drake41796911999-07-02 14:25:37 +0000125\withsubitem{(copy protocol)}{\ttindex{__getinitargs__()}}
126\withsubitem{(instance constructor)}{\ttindex{__init__()}}
Guido van Rossumd1883581995-02-15 15:53:08 +0000127
Fred Drake41796911999-07-02 14:25:37 +0000128Classes can further influence how their instances are pickled --- if
129the class
130\withsubitem{(copy protocol)}{
131 \ttindex{__getstate__()}\ttindex{__setstate__()}}
132\withsubitem{(instance attribute)}{
133 \ttindex{__dict__}}
Fred Drake9b28fe21998-04-04 06:20:28 +0000134defines the method \method{__getstate__()}, it is called and the return
Guido van Rossumd1883581995-02-15 15:53:08 +0000135state is pickled as the contents for the instance, and if the class
Fred Drake9b28fe21998-04-04 06:20:28 +0000136defines the method \method{__setstate__()}, it is called with the
Guido van Rossumd1883581995-02-15 15:53:08 +0000137unpickled state. (Note that these methods can also be used to
138implement copying class instances.) If there is no
Fred Drake9b28fe21998-04-04 06:20:28 +0000139\method{__getstate__()} method, the instance's \member{__dict__} is
140pickled. If there is no \method{__setstate__()} method, the pickled
Guido van Rossumd1883581995-02-15 15:53:08 +0000141object must be a dictionary and its items are assigned to the new
Fred Drake9b28fe21998-04-04 06:20:28 +0000142instance's dictionary. (If a class defines both \method{__getstate__()}
143and \method{__setstate__()}, the state object needn't be a dictionary
Guido van Rossumd1883581995-02-15 15:53:08 +0000144--- these methods can do what they want.) This protocol is also used
Fred Drakeffbe6871999-04-22 21:23:22 +0000145by the shallow and deep copying operations defined in the
146\refmodule{copy}\refstmodindex{copy} module.
Guido van Rossumd1883581995-02-15 15:53:08 +0000147
148Note that when class instances are pickled, their class's code and
Guido van Rossum6bb1adc1995-03-13 10:03:32 +0000149data are not pickled along with them. Only the instance data are
Guido van Rossumd1883581995-02-15 15:53:08 +0000150pickled. This is done on purpose, so you can fix bugs in a class or
151add methods and still load objects that were created with an earlier
152version of the class. If you plan to have long-lived objects that
Guido van Rossum6bb1adc1995-03-13 10:03:32 +0000153will see many versions of a class, it may be worthwhile to put a version
Guido van Rossumd1883581995-02-15 15:53:08 +0000154number in the objects so that suitable conversions can be made by the
Fred Drake9b28fe21998-04-04 06:20:28 +0000155class's \method{__setstate__()} method.
Guido van Rossumd1883581995-02-15 15:53:08 +0000156
Guido van Rossum470be141995-03-17 16:07:09 +0000157When a class itself is pickled, only its name is pickled --- the class
158definition is not pickled, but re-imported by the unpickling process.
159Therefore, the restriction that the class must be defined at the top
160level in a module applies to pickled classes as well.
161
Fred Drake19479911998-02-13 06:58:54 +0000162\setindexsubitem{(in module pickle)}
Guido van Rossum470be141995-03-17 16:07:09 +0000163
Guido van Rossumd1883581995-02-15 15:53:08 +0000164The interface can be summarized as follows.
165
166To pickle an object \code{x} onto a file \code{f}, open for writing:
167
Fred Drake19479911998-02-13 06:58:54 +0000168\begin{verbatim}
Guido van Rossumd1883581995-02-15 15:53:08 +0000169p = pickle.Pickler(f)
170p.dump(x)
Fred Drake19479911998-02-13 06:58:54 +0000171\end{verbatim}
Fred Drake9b28fe21998-04-04 06:20:28 +0000172
Guido van Rossum470be141995-03-17 16:07:09 +0000173A shorthand for this is:
174
Fred Drake19479911998-02-13 06:58:54 +0000175\begin{verbatim}
Guido van Rossum470be141995-03-17 16:07:09 +0000176pickle.dump(x, f)
Fred Drake19479911998-02-13 06:58:54 +0000177\end{verbatim}
Fred Drake9b28fe21998-04-04 06:20:28 +0000178
Guido van Rossumd1883581995-02-15 15:53:08 +0000179To unpickle an object \code{x} from a file \code{f}, open for reading:
180
Fred Drake19479911998-02-13 06:58:54 +0000181\begin{verbatim}
Guido van Rossumd1883581995-02-15 15:53:08 +0000182u = pickle.Unpickler(f)
Guido van Rossum96628a91995-04-10 11:34:00 +0000183x = u.load()
Fred Drake19479911998-02-13 06:58:54 +0000184\end{verbatim}
Fred Drake9b28fe21998-04-04 06:20:28 +0000185
Guido van Rossum470be141995-03-17 16:07:09 +0000186A shorthand is:
187
Fred Drake19479911998-02-13 06:58:54 +0000188\begin{verbatim}
Guido van Rossum470be141995-03-17 16:07:09 +0000189x = pickle.load(f)
Fred Drake19479911998-02-13 06:58:54 +0000190\end{verbatim}
Fred Drake9b28fe21998-04-04 06:20:28 +0000191
192The \class{Pickler} class only calls the method \code{f.write()} with a
Fred Drake38e5d272000-04-03 20:13:55 +0000193\withsubitem{(class in pickle)}{\ttindex{Unpickler}\ttindex{Pickler}}
Fred Drake9b28fe21998-04-04 06:20:28 +0000194string argument. The \class{Unpickler} calls the methods \code{f.read()}
Fred Drakecf7e8301998-01-09 22:36:51 +0000195(with an integer argument) and \code{f.readline()} (without argument),
Guido van Rossumd1883581995-02-15 15:53:08 +0000196both returning a string. It is explicitly allowed to pass non-file
197objects here, as long as they have the right methods.
198
Fred Drake9b28fe21998-04-04 06:20:28 +0000199The constructor for the \class{Pickler} class has an optional second
Fred Drake38e5d272000-04-03 20:13:55 +0000200argument, \var{bin}. If this is present and true, the binary
201pickle format is used; if it is absent or false, the (less efficient,
Guido van Rossum736fe5e1997-12-09 20:45:08 +0000202but backwards compatible) text pickle format is used. The
Fred Drake9b28fe21998-04-04 06:20:28 +0000203\class{Unpickler} class does not have an argument to distinguish
Guido van Rossum736fe5e1997-12-09 20:45:08 +0000204between binary and text pickle formats; it accepts either format.
205
Guido van Rossumd1883581995-02-15 15:53:08 +0000206The following types can be pickled:
Fred Drake41796911999-07-02 14:25:37 +0000207
Guido van Rossumd1883581995-02-15 15:53:08 +0000208\begin{itemize}
209
210\item \code{None}
211
212\item integers, long integers, floating point numbers
213
Fred Drake56ced2a2000-04-06 15:04:30 +0000214\item normal and Unicode strings
Guido van Rossumd1883581995-02-15 15:53:08 +0000215
216\item tuples, lists and dictionaries containing only picklable objects
217
Fred Drake38e5d272000-04-03 20:13:55 +0000218\item functions defined at the top level of a module (by name
219 reference, not storage of the implementation)
220
221\item built-in functions
222
Guido van Rossum470be141995-03-17 16:07:09 +0000223\item classes that are defined at the top level in a module
224
Fred Drake9b28fe21998-04-04 06:20:28 +0000225\item instances of such classes whose \member{__dict__} or
226\method{__setstate__()} is picklable
Guido van Rossumd1883581995-02-15 15:53:08 +0000227
228\end{itemize}
229
Guido van Rossum470be141995-03-17 16:07:09 +0000230Attempts to pickle unpicklable objects will raise the
Fred Drake9b28fe21998-04-04 06:20:28 +0000231\exception{PicklingError} exception; when this happens, an unspecified
Guido van Rossum470be141995-03-17 16:07:09 +0000232number of bytes may have been written to the file.
Guido van Rossumd1883581995-02-15 15:53:08 +0000233
Fred Drake9b28fe21998-04-04 06:20:28 +0000234It is possible to make multiple calls to the \method{dump()} method of
235the same \class{Pickler} instance. These must then be matched to the
236same number of calls to the \method{load()} method of the
237corresponding \class{Unpickler} instance. If the same object is
238pickled by multiple \method{dump()} calls, the \method{load()} will all
Fred Drakecf7e8301998-01-09 22:36:51 +0000239yield references to the same object. \emph{Warning}: this is intended
Guido van Rossum470be141995-03-17 16:07:09 +0000240for pickling multiple objects without intervening modifications to the
241objects or their parts. If you modify an object and then pickle it
Fred Drake9b28fe21998-04-04 06:20:28 +0000242again using the same \class{Pickler} instance, the object is not
Guido van Rossum470be141995-03-17 16:07:09 +0000243pickled again --- a reference to it is pickled and the
Fred Drake9b28fe21998-04-04 06:20:28 +0000244\class{Unpickler} will return the old value, not the modified one.
Guido van Rossum470be141995-03-17 16:07:09 +0000245(There are two problems here: (a) detecting changes, and (b)
246marshalling a minimal set of changes. I have no answers. Garbage
247Collection may also become a problem here.)
248
Fred Drake9b28fe21998-04-04 06:20:28 +0000249Apart from the \class{Pickler} and \class{Unpickler} classes, the
Guido van Rossum470be141995-03-17 16:07:09 +0000250module defines the following functions, and an exception:
251
Fred Drakecce10901998-03-17 06:33:25 +0000252\begin{funcdesc}{dump}{object, file\optional{, bin}}
Guido van Rossum470be141995-03-17 16:07:09 +0000253Write a pickled representation of \var{obect} to the open file object
Guido van Rossum736fe5e1997-12-09 20:45:08 +0000254\var{file}. This is equivalent to
Fred Drake9b28fe21998-04-04 06:20:28 +0000255\samp{Pickler(\var{file}, \var{bin}).dump(\var{object})}.
Guido van Rossum736fe5e1997-12-09 20:45:08 +0000256If the optional \var{bin} argument is present and nonzero, the binary
257pickle format is used; if it is zero or absent, the (less efficient)
258text pickle format is used.
Guido van Rossum470be141995-03-17 16:07:09 +0000259\end{funcdesc}
260
261\begin{funcdesc}{load}{file}
262Read a pickled object from the open file object \var{file}. This is
Fred Drake9b28fe21998-04-04 06:20:28 +0000263equivalent to \samp{Unpickler(\var{file}).load()}.
Guido van Rossum470be141995-03-17 16:07:09 +0000264\end{funcdesc}
265
Guido van Rossum736fe5e1997-12-09 20:45:08 +0000266\begin{funcdesc}{dumps}{object\optional{, bin}}
Guido van Rossum470be141995-03-17 16:07:09 +0000267Return the pickled representation of the object as a string, instead
Guido van Rossum736fe5e1997-12-09 20:45:08 +0000268of writing it to a file. If the optional \var{bin} argument is
269present and nonzero, the binary pickle format is used; if it is zero
270or absent, the (less efficient) text pickle format is used.
Guido van Rossum470be141995-03-17 16:07:09 +0000271\end{funcdesc}
272
273\begin{funcdesc}{loads}{string}
274Read a pickled object from a string instead of a file. Characters in
275the string past the pickled object's representation are ignored.
276\end{funcdesc}
277
278\begin{excdesc}{PicklingError}
279This exception is raised when an unpicklable object is passed to
Fred Drake41796911999-07-02 14:25:37 +0000280\method{Pickler.dump()}.
Guido van Rossum470be141995-03-17 16:07:09 +0000281\end{excdesc}
Fred Drake40748961998-03-06 21:27:14 +0000282
283
284\begin{seealso}
Fred Drakeffbe6871999-04-22 21:23:22 +0000285 \seemodule[copyreg]{copy_reg}{pickle interface constructor
286 registration}
Fred Drake9b28fe21998-04-04 06:20:28 +0000287
Fred Drakeffbe6871999-04-22 21:23:22 +0000288 \seemodule{shelve}{indexed databases of objects; uses \module{pickle}}
Fred Drake17e56401998-04-11 20:43:51 +0000289
Fred Drakeffbe6871999-04-22 21:23:22 +0000290 \seemodule{copy}{shallow and deep object copying}
Fred Drake17e56401998-04-11 20:43:51 +0000291
Fred Drakeffbe6871999-04-22 21:23:22 +0000292 \seemodule{marshal}{high-performance serialization of built-in types}
Fred Drake40748961998-03-06 21:27:14 +0000293\end{seealso}
Fred Drake9463de21998-04-11 20:05:43 +0000294
295
Fred Drake38e5d272000-04-03 20:13:55 +0000296\subsection{Example \label{pickle-example}}
297
298Here's a simple example of how to modify pickling behavior for a
299class. The \class{TextReader} class opens a text file, and returns
300the line number and line contents each time its \method{readline()}
301method is called. If a \class{TextReader} instance is pickled, all
302attributes \emph{except} the file object member are saved. When the
303instance is unpickled, the file is reopened, and reading resumes from
304the last location. The \method{__setstate__()} and
305\method{__getstate__()} methods are used to implement this behavior.
306
307\begin{verbatim}
308# illustrate __setstate__ and __getstate__ methods
309# used in pickling.
310
311class TextReader:
312 "Print and number lines in a text file."
313 def __init__(self,file):
314 self.file = file
315 self.fh = open(file,'r')
316 self.lineno = 0
317
318 def readline(self):
319 self.lineno = self.lineno + 1
320 line = self.fh.readline()
321 if not line:
322 return None
323 return "%d: %s" % (self.lineno,line[:-1])
324
325 # return data representation for pickled object
326 def __getstate__(self):
327 odict = self.__dict__ # get attribute dictionary
328 del odict['fh'] # remove filehandle entry
329 return odict
330
331 # restore object state from data representation generated
332 # by __getstate__
333 def __setstate__(self,dict):
334 fh = open(dict['file']) # reopen file
335 count = dict['lineno'] # read from file...
336 while count: # until line count is restored
337 fh.readline()
338 count = count - 1
339 dict['fh'] = fh # create filehandle entry
340 self.__dict__ = dict # make dict our attribute dictionary
341\end{verbatim}
342
343A sample usage might be something like this:
344
345\begin{verbatim}
346>>> import TextReader
347>>> obj = TextReader.TextReader("TextReader.py")
348>>> obj.readline()
349'1: #!/usr/local/bin/python'
350>>> # (more invocations of obj.readline() here)
351... obj.readline()
352'7: class TextReader:'
353>>> import pickle
354>>> pickle.dump(obj,open('save.p','w'))
355
356 (start another Python session)
357
358>>> import pickle
359>>> reader = pickle.load(open('save.p'))
360>>> reader.readline()
361'8: "Print and number lines in a text file."'
362\end{verbatim}
363
364
Fred Drake295da241998-08-10 19:42:37 +0000365\section{\module{cPickle} ---
Fred Drakeffbe6871999-04-22 21:23:22 +0000366 Alternate implementation of \module{pickle}}
367
Fred Drakeb91e9341998-07-23 17:59:49 +0000368\declaremodule{builtin}{cPickle}
Fred Drake38e5d272000-04-03 20:13:55 +0000369\modulesynopsis{Faster version of \refmodule{pickle}, but not subclassable.}
Fred Drakeffbe6871999-04-22 21:23:22 +0000370\moduleauthor{Jim Fulton}{jfulton@digicool.com}
371\sectionauthor{Fred L. Drake, Jr.}{fdrake@acm.org}
Fred Drakeb91e9341998-07-23 17:59:49 +0000372
Fred Drake9463de21998-04-11 20:05:43 +0000373
Fred Drake9463de21998-04-11 20:05:43 +0000374The \module{cPickle} module provides a similar interface and identical
Fred Drake41796911999-07-02 14:25:37 +0000375functionality as the \refmodule{pickle}\refstmodindex{pickle} module,
376but can be up to 1000 times faster since it is implemented in C. The
377only other important difference to note is that \function{Pickler()}
378and \function{Unpickler()} are functions and not classes, and so
379cannot be subclassed. This should not be an issue in most cases.
Fred Drake9463de21998-04-11 20:05:43 +0000380
381The format of the pickle data is identical to that produced using the
Fred Drakeffbe6871999-04-22 21:23:22 +0000382\refmodule{pickle} module, so it is possible to use \refmodule{pickle} and
Fred Drake9463de21998-04-11 20:05:43 +0000383\module{cPickle} interchangably with existing pickles.
Guido van Rossumcf3ce921999-01-06 23:34:39 +0000384
385(Since the pickle data format is actually a tiny stack-oriented
386programming language, and there are some freedoms in the encodings of
387certain objects, it's possible that the two modules produce different
388pickled data for the same input objects; however they will always be
Fred Drakec3a65982000-07-01 17:47:38 +0000389able to read each other's pickles back in.)