Lines Matching refs:pickle

1 :mod:`pickle` --- Python object serialization
12 .. module:: pickle
17 The :mod:`pickle` module implements a fundamental, but powerful algorithm for
25 This documentation describes both the :mod:`pickle` module and the
30 The :mod:`pickle` module is not secure against erroneous or maliciously
38 The :mod:`pickle` module has an optimized cousin called the :mod:`cPickle`
40 1000 times faster than :mod:`pickle`. However it does not support subclassing
46 where necessary. In the following discussions, we use the term "pickle" to
47 collectively describe the :mod:`pickle` and :mod:`cPickle` modules.
52 general :mod:`pickle` should always be the preferred way to serialize Python
56 The :mod:`pickle` module differs from :mod:`marshal` in several significant ways:
58 * The :mod:`pickle` module keeps track of the objects it has already serialized,
67 serialized. :mod:`pickle` stores such objects only once, and ensures that all
72 instances. :mod:`pickle` can save and restore class instances transparently,
80 The :mod:`pickle` serialization format is guaranteed to be backwards compatible
84 :mod:`pickle` reads and writes file objects, it does not handle the issue of
86 access to persistent objects. The :mod:`pickle` module can transform a complex
91 :mod:`shelve` provides a simple interface to pickle and unpickle objects on
102 The data format used by :mod:`pickle` is Python-specific. This has the
107 By default, the :mod:`pickle` data format uses a printable ASCII representation.
110 :mod:`pickle`'s representation) is that for debugging or recovery purposes it is
143 :mod:`pickle` module provides the following constant:
155 Be sure to always open pickle files created with protocols >= 1 in binary mode.
156 For the old ASCII-based pickle protocol 0 you can use either text mode or binary
159 A pickle file written with protocol 0 in binary mode will contain lone linefeeds
163 The :mod:`pickle` module provides the following functions to make the pickling
186 Read a string from the open file object *file* and interpret it as a pickle data
218 The :mod:`pickle` module also defines three exceptions:
240 The :mod:`pickle` module also exports two callables [#]_, :class:`Pickler` and
246 This takes a file-like object to which it will write a pickle data stream.
279 created by :mod:`cPickle`. In the :mod:`pickle` module, picklers have an
281 the memo for a :mod:`pickle` module pickler, you could do the following::
299 This takes a file-like object from which it will read a pickle data stream.
327 ids" that may be referenced in a pickle data stream. See section
328 :ref:`pickle-protocol` below for more details.
332 :mod:`pickle` module :class:`Unpickler`\ s do not have the :meth:`noload`
356 calling :meth:`__getstate__` is picklable (see section :ref:`pickle-protocol`
359 Attempts to pickle unpicklable objects will raise the :exc:`PicklingError`
361 been written to the underlying file. Trying to pickle a highly recursive data
381 picklestring = pickle.dumps(Foo)
397 The pickle protocol
407 environment slightly safer from untrusted pickle data streams; see section
408 :ref:`pickle-sub` for more details.
424 method is called at pickle time; the tuple it returns is incorporated in the
425 pickle for the instance.
480 how to pickle it. One alternative is for the object to implement a
487 object's local name relative to its module; the pickle module searches the
513 :meth:`__setstate__` method as described in section :ref:`pickle-inst`. If
524 depends on which pickle protocol version is used as well as the number of
563 single: persistent_id (pickle protocol)
564 single: persistent_load (pickle protocol)
566 For the benefit of object persistence, the :mod:`pickle` module supports the
570 the :mod:`pickle` module; it will delegate this resolution to user defined
577 To pickle objects that have an external persistent id, the pickler must have a
581 When a persistent id string is returned, the pickler will pickle that string,
591 import pickle
595 p = pickle.Pickler(src)
619 up = pickle.Unpickler(dst)
630 raise pickle.UnpicklingError, 'Invalid persistent id'
640 this list. This functionality exists so that a pickle data stream can be
642 in a pickle.
646 .. BAW: Both pickle and cPickle support something called inst_persistent_id()
658 single: load_global() (pickle protocol)
659 single: find_global() (pickle protocol)
661 By default, unpickling will import any class that it finds in the pickle data.
664 on whether you're using :mod:`pickle` or :mod:`cPickle`. [#]_
666 In the :mod:`pickle` module, you need to derive a subclass from
668 :meth:`load_global` should read two lines from the pickle data stream where the
702 import pickle
714 pickle.dump(data1, output)
717 pickle.dump(selfref_list, output, -1)
722 pickle-containing file, you should open the file in binary mode because you
725 import pprint, pickle
729 data1 = pickle.load(pkl_file)
732 data2 = pickle.load(pkl_file)
787 >>> import pickle
788 >>> pickle.dump(obj, open('save.p', 'wb'))
790 If you want to see that :mod:`pickle` works across Python processes, start
794 >>> import pickle
795 >>> reader = pickle.load(open('save.p', 'rb'))
806 Indexed databases of objects; uses :mod:`pickle`.
815 :mod:`cPickle` --- A faster :mod:`pickle`
819 :synopsis: Faster version of pickle, but not subclassable.
824 .. index:: module: pickle
828 :mod:`pickle` module. There are several differences, the most important being
831 First, :mod:`cPickle` can be up to 1000 times faster than :mod:`pickle` because
838 The pickle data stream produced by :mod:`pickle` and :mod:`cPickle` are
839 identical, so it is possible to use :mod:`pickle` and :mod:`cPickle`
843 :mod:`pickle`, however for most applications, they are interchangeable. More
844 documentation is provided in the :mod:`pickle` module documentation, which
851 .. [#] In the :mod:`pickle` module these callables are classes, which you could
855 :ref:`pickle-sub` for more details.
859 pickle it again using the same :class:`Pickler` instance, the object is not
874 different for :mod:`pickle` and :mod:`cPickle`. The description given here
875 works the same for both implementations. Users of the :mod:`pickle` module
886 work in either :mod:`pickle` or :mod:`cPickle`.
888 .. [#] Since the pickle data format is actually a tiny stack-oriented programming