mirror of
https://github.com/python/cpython.git
synced 2025-08-24 18:55:00 +00:00
Doc: Update pickle.rst (GH-14128) (GH-16014)
* Edits for readability and grammar
(cherry picked from commit 362f5350eb
)
Co-authored-by: Géry Ogam <gery.ogam@gmail.com>
This commit is contained in:
parent
2bb6bf0c8c
commit
eb19c45298
1 changed files with 19 additions and 17 deletions
|
@ -211,8 +211,9 @@ process more convenient:
|
||||||
|
|
||||||
.. function:: dump(obj, file, protocol=None, \*, fix_imports=True, buffer_callback=None)
|
.. function:: dump(obj, file, protocol=None, \*, fix_imports=True, buffer_callback=None)
|
||||||
|
|
||||||
Write a pickled representation of *obj* to the open :term:`file object` *file*.
|
Write the pickled representation of the object *obj* to the open
|
||||||
This is equivalent to ``Pickler(file, protocol).dump(obj)``.
|
:term:`file object` *file*. This is equivalent to
|
||||||
|
``Pickler(file, protocol).dump(obj)``.
|
||||||
|
|
||||||
Arguments *file*, *protocol*, *fix_imports* and *buffer_callback* have
|
Arguments *file*, *protocol*, *fix_imports* and *buffer_callback* have
|
||||||
the same meaning as in the :class:`Pickler` constructor.
|
the same meaning as in the :class:`Pickler` constructor.
|
||||||
|
@ -222,7 +223,7 @@ process more convenient:
|
||||||
|
|
||||||
.. function:: dumps(obj, protocol=None, \*, fix_imports=True, buffer_callback=None)
|
.. function:: dumps(obj, protocol=None, \*, fix_imports=True, buffer_callback=None)
|
||||||
|
|
||||||
Return the pickled representation of the object as a :class:`bytes` object,
|
Return the pickled representation of the object *obj* as a :class:`bytes` object,
|
||||||
instead of writing it to a file.
|
instead of writing it to a file.
|
||||||
|
|
||||||
Arguments *protocol*, *fix_imports* and *buffer_callback* have the same
|
Arguments *protocol*, *fix_imports* and *buffer_callback* have the same
|
||||||
|
@ -233,13 +234,13 @@ process more convenient:
|
||||||
|
|
||||||
.. function:: load(file, \*, fix_imports=True, encoding="ASCII", errors="strict", buffers=None)
|
.. function:: load(file, \*, fix_imports=True, encoding="ASCII", errors="strict", buffers=None)
|
||||||
|
|
||||||
Read a pickled object representation from the open :term:`file object`
|
Read the pickled representation of an object from the open :term:`file object`
|
||||||
*file* and return the reconstituted object hierarchy specified therein.
|
*file* and return the reconstituted object hierarchy specified therein.
|
||||||
This is equivalent to ``Unpickler(file).load()``.
|
This is equivalent to ``Unpickler(file).load()``.
|
||||||
|
|
||||||
The protocol version of the pickle is detected automatically, so no
|
The protocol version of the pickle is detected automatically, so no
|
||||||
protocol argument is needed. Bytes past the pickled object's
|
protocol argument is needed. Bytes past the pickled representation
|
||||||
representation are ignored.
|
of the object are ignored.
|
||||||
|
|
||||||
Arguments *file*, *fix_imports*, *encoding*, *errors*, *strict* and *buffers*
|
Arguments *file*, *fix_imports*, *encoding*, *errors*, *strict* and *buffers*
|
||||||
have the same meaning as in the :class:`Unpickler` constructor.
|
have the same meaning as in the :class:`Unpickler` constructor.
|
||||||
|
@ -249,12 +250,12 @@ process more convenient:
|
||||||
|
|
||||||
.. function:: loads(bytes_object, \*, fix_imports=True, encoding="ASCII", errors="strict", buffers=None)
|
.. function:: loads(bytes_object, \*, fix_imports=True, encoding="ASCII", errors="strict", buffers=None)
|
||||||
|
|
||||||
Read a pickled object hierarchy from a :class:`bytes` object and return the
|
Return the reconstituted object hierarchy of the pickled representation
|
||||||
reconstituted object hierarchy specified therein.
|
*bytes_object* of an object.
|
||||||
|
|
||||||
The protocol version of the pickle is detected automatically, so no
|
The protocol version of the pickle is detected automatically, so no
|
||||||
protocol argument is needed. Bytes past the pickled object's
|
protocol argument is needed. Bytes past the pickled representation
|
||||||
representation are ignored.
|
of the object are ignored.
|
||||||
|
|
||||||
Arguments *file*, *fix_imports*, *encoding*, *errors*, *strict* and *buffers*
|
Arguments *file*, *fix_imports*, *encoding*, *errors*, *strict* and *buffers*
|
||||||
have the same meaning as in the :class:`Unpickler` constructor.
|
have the same meaning as in the :class:`Unpickler` constructor.
|
||||||
|
@ -325,7 +326,7 @@ The :mod:`pickle` module exports three classes, :class:`Pickler`,
|
||||||
|
|
||||||
.. method:: dump(obj)
|
.. method:: dump(obj)
|
||||||
|
|
||||||
Write a pickled representation of *obj* to the open file object given in
|
Write the pickled representation of *obj* to the open file object given in
|
||||||
the constructor.
|
the constructor.
|
||||||
|
|
||||||
.. method:: persistent_id(obj)
|
.. method:: persistent_id(obj)
|
||||||
|
@ -426,9 +427,10 @@ The :mod:`pickle` module exports three classes, :class:`Pickler`,
|
||||||
|
|
||||||
.. method:: load()
|
.. method:: load()
|
||||||
|
|
||||||
Read a pickled object representation from the open file object given in
|
Read the pickled representation of an object from the open file object
|
||||||
the constructor, and return the reconstituted object hierarchy specified
|
given in the constructor, and return the reconstituted object hierarchy
|
||||||
therein. Bytes past the pickled object's representation are ignored.
|
specified therein. Bytes past the pickled representation of the object
|
||||||
|
are ignored.
|
||||||
|
|
||||||
.. method:: persistent_load(pid)
|
.. method:: persistent_load(pid)
|
||||||
|
|
||||||
|
@ -731,13 +733,13 @@ alphanumeric characters (for protocol 0) [#]_ or just an arbitrary object (for
|
||||||
any newer protocol).
|
any newer protocol).
|
||||||
|
|
||||||
The resolution of such persistent IDs is not defined by the :mod:`pickle`
|
The resolution of such persistent IDs is not defined by the :mod:`pickle`
|
||||||
module; it will delegate this resolution to the user defined methods on the
|
module; it will delegate this resolution to the user-defined methods on the
|
||||||
pickler and unpickler, :meth:`~Pickler.persistent_id` and
|
pickler and unpickler, :meth:`~Pickler.persistent_id` and
|
||||||
:meth:`~Unpickler.persistent_load` respectively.
|
:meth:`~Unpickler.persistent_load` respectively.
|
||||||
|
|
||||||
To pickle objects that have an external persistent id, the pickler must have a
|
To pickle objects that have an external persistent ID, the pickler must have a
|
||||||
custom :meth:`~Pickler.persistent_id` method that takes an object as an
|
custom :meth:`~Pickler.persistent_id` method that takes an object as an
|
||||||
argument and returns either ``None`` or the persistent id for that object.
|
argument and returns either ``None`` or the persistent ID for that object.
|
||||||
When ``None`` is returned, the pickler simply pickles the object as normal.
|
When ``None`` is returned, the pickler simply pickles the object as normal.
|
||||||
When a persistent ID string is returned, the pickler will pickle that object,
|
When a persistent ID string is returned, the pickler will pickle that object,
|
||||||
along with a marker so that the unpickler will recognize it as a persistent ID.
|
along with a marker so that the unpickler will recognize it as a persistent ID.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue