Lines Matching +full:object +full:- +full:copy
1 :mod:`copy` --- Shallow and deep copy operations
4 .. module:: copy
5 :synopsis: Shallow and deep copy operations.
7 **Source code:** :source:`Lib/copy.py`
9 --------------
11 Assignment statements in Python do not copy objects, they create bindings
12 between a target and an object. For collections that are mutable or contain
13 mutable items, a copy is sometimes needed so one can change one copy without
14 changing the other. This module provides generic shallow and deep copy
20 .. function:: copy(x)
22 Return a shallow copy of *x*.
27 Return a deep copy of *x*.
39 * A *shallow copy* constructs a new compound object and then (to the extent
42 * A *deep copy* constructs a new compound object and then, recursively, inserts
45 Two problems often exist with deep copy operations that don't exist with shallow
46 copy operations:
51 * Because deep copy copies everything it may copy too much, such as data
59 * letting user-defined classes override the copying operation or the set of
62 This module does not copy types like module, method, stack trace, stack frame,
63 file, socket, window, or any similar types. It does "copy" functions and
64 classes (shallow and deeply), by returning the original object unchanged; this
67 Shallow copies of dictionaries can be made using :meth:`dict.copy`, and
75 methods. In fact, the :mod:`copy` module uses the registered
79 single: __copy__() (copy protocol)
80 single: __deepcopy__() (copy protocol)
82 In order for a class to define its own copy implementation, it can define
84 to implement the shallow copy operation; no additional arguments are passed.
85 The latter is called to implement the deep copy operation; it is passed one
87 to make a deep copy of a component, it should call the :func:`deepcopy` function
89 The memo dictionary should be treated as an opaque object.
95 Discussion of the special methods used to support object state retrieval and