Changeset 391 for python/trunk/Doc/library/copy_reg.rst
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Doc/library/copy_reg.rst
r2 r391 6 6 7 7 .. note:: 8 The :mod:`copy_reg` module has been renamed to :mod:`copyreg` in Python 3. 0.8 The :mod:`copy_reg` module has been renamed to :mod:`copyreg` in Python 3. 9 9 The :term:`2to3` tool will automatically adapt imports when converting your 10 sources to 3.0.10 sources to Python 3. 11 11 12 12 .. index:: … … 15 15 module: copy 16 16 17 The :mod:`copy_reg` module provides support for the :mod:`pickle` and18 :mod:`cPickle` modules. The :mod:`copy` module is likely to use this in the 19 future as well. It provides configuration information about object constructors20 which are not classes. Such constructors may be factory functions or class 21 instances.17 The :mod:`copy_reg` module offers a way to define fuctions used while pickling 18 specific objects. The :mod:`pickle`, :mod:`cPickle`, and :mod:`copy` modules 19 use those functions when pickling/copying those objects. The module provides 20 configuration information about object constructors which are not classes. 21 Such constructors may be factory functions or class instances. 22 22 23 23 … … 44 44 *function* and *constructor*. 45 45 46 Example 47 ------- 48 49 The example below would like to show how to register a pickle function and how 50 it will be used: 51 52 >>> import copy_reg, copy, pickle 53 >>> class C(object): 54 ... def __init__(self, a): 55 ... self.a = a 56 ... 57 >>> def pickle_c(c): 58 ... print("pickling a C instance...") 59 ... return C, (c.a,) 60 ... 61 >>> copy_reg.pickle(C, pickle_c) 62 >>> c = C(1) 63 >>> d = copy.copy(c) 64 pickling a C instance... 65 >>> p = pickle.dumps(c) 66 pickling a C instance...
Note:
See TracChangeset
for help on using the changeset viewer.