next up previous contents
Next: Documentation Strings Up: Object Persistency and Previous: Persistent Objects

Copying Objects

The module copy exports two functions: copy() and deepcopy(). The copy() function returns a ``shallow'' copy of an object; deepcopy() returns a ``deep'' copy. The difference between shallow and deep copying is only relevant for compound objects (objects that contain other objects, like lists or class instances):

Both functions have the same restrictions and use the same protocols as pickle --- user-defined classes can control how they are copied by providing methods named __getinitargs__(), __getstate__() and __setstate__().



guido@cwi.nl