Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
b1c0e3b2
Commit
b1c0e3b2
authored
Nov 08, 2012
by
Ezio Melotti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#11481: update copy_reg docs and add example.
parent
26025d63
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
5 deletions
+26
-5
Doc/library/copy_reg.rst
Doc/library/copy_reg.rst
+26
-5
No files found.
Doc/library/copy_reg.rst
View file @
b1c0e3b2
...
...
@@ -14,11 +14,11 @@
module: cPickle
module: copy
The :mod:`copy_reg` module
provides support for the :mod:`pickle` and
:mod:`cPickle` modules. The :mod:`copy` module is likely to use this in the
future as well. It provides configuration information about object constructor
s
which are not classes. Such constructors may be factory functions or class
instances.
The :mod:`copy_reg` module
offers a way to define fuctions used while pickling
specific objects. The :mod:`pickle`, :mod:`cPickle, and :mod:`copy` modules
use those functions when pickling/copying those objects. The module provide
s
configuration information about object constructors which are not classes.
Such constructors may be factory functions or class
instances.
.. function:: constructor(object)
...
...
@@ -43,3 +43,24 @@ instances.
See the :mod:`pickle` module for more details on the interface expected of
*function* and *constructor*.
Example
-------
The example below would like to show how to register a pickle function and how
it will be used:
>>> import copy_reg, copy, pickle
>>> class C(object):
... def __init__(self, a):
... self.a = a
...
>>> def pickle_c(c):
... print("pickling a C instance...")
... return C, (c.a,)
...
>>> copy_reg.pickle(C, pickle_c)
>>> c = C(1)
>>> d = copy.copy(c)
pickling a C instance...
>>> p = pickle.dumps(c)
pickling a C instance...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment