This module provides generic (shallow and deep) copying operations.
import copy x = copy.copy(y) # make a shallow copy of y x = copy.deepcopy(y) # make a deep copy of y
For module specific errors,
copy.error is raised.
The difference between shallow and deep copying is only relevant for compound objects (objects that contain other objects, like lists or class instances):
Two problems often exist with deep copy operations that don't exist with shallow copy operations:
deepcopy() operation avoids these problems by:
This version does not copy types like module, class, function, method, nor stack trace, stack frame, nor file, socket, window, nor array, nor any similar types.
Classes can use the same interfaces to control copying that they use
to control pickling: they can define methods called
__setstate__(). See the description of module
for information on these methods.