Kaydet (Commit) fda08b08 authored tarafından Antoine Pitrou's avatar Antoine Pitrou

Some nits in the pickle docs.

...@@ -85,45 +85,48 @@ Data stream format ...@@ -85,45 +85,48 @@ Data stream format
------------------ ------------------
.. index:: .. index::
single: XDR
single: External Data Representation single: External Data Representation
The data format used by :mod:`pickle` is Python-specific. This has the The data format used by :mod:`pickle` is Python-specific. This has the
advantage that there are no restrictions imposed by external standards such as advantage that there are no restrictions imposed by external standards such as
XDR (which can't represent pointer sharing); however it means that non-Python JSON or XDR (which can't represent pointer sharing); however it means that
programs may not be able to reconstruct pickled Python objects. non-Python programs may not be able to reconstruct pickled Python objects.
By default, the :mod:`pickle` data format uses a relatively compact binary
representation. If you need optimal size characteristics, you can efficiently
:doc:`compress <archiving>` pickled data.
By default, the :mod:`pickle` data format uses a compact binary representation.
The module :mod:`pickletools` contains tools for analyzing data streams The module :mod:`pickletools` contains tools for analyzing data streams
generated by :mod:`pickle`. generated by :mod:`pickle`. :mod:`pickletools` source code has extensive
comments about opcodes used by pickle protocols.
There are currently 4 different protocols which can be used for pickling. There are currently 4 different protocols which can be used for pickling.
* Protocol version 0 is the original human-readable protocol and is * Protocol version 0 is the original "human-readable" protocol and is
backwards compatible with earlier versions of Python. backwards compatible with earlier versions of Python.
* Protocol version 1 is the old binary format which is also compatible with * Protocol version 1 is an old binary format which is also compatible with
earlier versions of Python. earlier versions of Python.
* Protocol version 2 was introduced in Python 2.3. It provides much more * Protocol version 2 was introduced in Python 2.3. It provides much more
efficient pickling of :term:`new-style class`\es. efficient pickling of :term:`new-style class`\es. Refer to :pep:`307` for
information about improvements brought by protocol 2.
* Protocol version 3 was added in Python 3.0. It has explicit support for * Protocol version 3 was added in Python 3. It has explicit support for
bytes and cannot be unpickled by Python 2.x pickle modules. This is :class:`bytes` objects and cannot be unpickled by Python 2.x. This is
the current recommended protocol, use it whenever it is possible. the default as well as the current recommended protocol; use it whenever
possible.
Refer to :pep:`307` for information about improvements brought by
protocol 2. See :mod:`pickletools`'s source code for extensive
comments about opcodes used by pickle protocols.
Module Interface Module Interface
---------------- ----------------
To serialize an object hierarchy, you first create a pickler, then you call the To serialize an object hierarchy, you simply call the :func:`dumps` function.
pickler's :meth:`dump` method. To de-serialize a data stream, you first create Similarly, to de-serialize a data stream, you call the :func:`loads` function.
an unpickler, then you call the unpickler's :meth:`load` method. The However, if you want more control over serialization and de-serialization,
:mod:`pickle` module provides the following constant: you can create a :class:`Pickler` or an :class:`Unpickler` object, respectively.
The :mod:`pickle` module provides the following constants:
.. data:: HIGHEST_PROTOCOL .. data:: HIGHEST_PROTOCOL
...@@ -134,8 +137,7 @@ an unpickler, then you call the unpickler's :meth:`load` method. The ...@@ -134,8 +137,7 @@ an unpickler, then you call the unpickler's :meth:`load` method. The
.. data:: DEFAULT_PROTOCOL .. data:: DEFAULT_PROTOCOL
The default protocol used for pickling. May be less than HIGHEST_PROTOCOL. The default protocol used for pickling. May be less than HIGHEST_PROTOCOL.
Currently the default protocol is 3; a backward-incompatible protocol Currently the default protocol is 3, a new protocol designed for Python 3.0.
designed for Python 3.0.
The :mod:`pickle` module provides the following functions to make the pickling The :mod:`pickle` module provides the following functions to make the pickling
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment