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
3c9f05a5
Commit
3c9f05a5
authored
Nov 30, 1998
by
Fred Drake
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Markup improvements to help with conversions.
parent
ed980be7
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
27 deletions
+33
-27
Doc/lib/libcopy.tex
Doc/lib/libcopy.tex
+33
-27
No files found.
Doc/lib/libcopy.tex
View file @
3c9f05a5
...
...
@@ -4,9 +4,9 @@
\modulesynopsis
{
Shallow and deep copy operations.
}
\
setindexsubitem
{
(copy function)
}
\ttindex
{
copy
}
\ttindex
{
deepcopy
}
\
withsubitem
{
(in module copy)
}{
%
\ttindex
{
copy
}
%
\ttindex
{
deepcopy
}
}
This module provides generic (shallow and deep) copying operations.
...
...
@@ -19,7 +19,7 @@ x = copy.copy(y) # make a shallow copy of y
x = copy.deepcopy(y) # make a deep copy of y
\end{verbatim}
%
For module specific errors,
\
code
{
copy.error
}
is raised.
For module specific errors,
\
exception
{
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
...
...
@@ -49,13 +49,13 @@ Recursive objects (compound objects that, directly or indirectly,
contain a reference to themselves) may cause a recursive loop.
\item
Because deep copy copies
\emph
{
everything
}
it may copy too much,
e.g.
\
administrative data structures that should be shared even betwe
en
copies.
Because deep copy copies
\emph
{
everything
}
it may copy too much,
e.g., administrative data structures that should be shared ev
en
between
copies.
\end{itemize}
Python's
\code
{
deepcopy()
}
opera
tion avoids these problems by:
The
\function
{
deepcopy()
}
func
tion avoids these problems by:
\begin{itemize}
...
...
@@ -75,24 +75,30 @@ any similar types.
Classes can use the same interfaces to control copying that they use
to control pickling: they can define methods called
\code
{__
getinitargs
__
()
}
,
\code
{__
getstate
__
()
}
and
\code
{__
setstate
__
()
}
. See the description of module
\code
{
pickle
}
for information on these methods.
The copy module does not use the
\module
{
copy
_
reg
}
registration
module.
\refstmodindex
{
pickle
}
\setindexsubitem
{
(copy protocol)
}
\ttindex
{__
getinitargs
__}
\ttindex
{__
getstate
__}
\ttindex
{__
setstate
__}
\method
{__
getinitargs
__
()
}
,
\method
{__
getstate
__
()
}
and
\method
{__
setstate
__
()
}
. See the description of module
\module
{
pickle
}
\refstmodindex
{
pickle
}
for information on these
methods. The
\module
{
copy
}
module does not use the
\module
{
copy
_
reg
}
registration module.
\withsubitem
{
(copy protocol)
}{
%
\ttindex
{__
getinitargs
__
()
}
%
\ttindex
{__
getstate
__
()
}
%
\ttindex
{__
setstate
__
()
}}
In order for a class to define its own copy implementation, it can
define special methods
\method
{__
copy
__
()
}
\ttindex
{__
copy
__}
and
\method
{__
deepcopy
__
()
}
\ttindex
{__
deepcopy
__}
. The former is called to
implement the shallow copy operation; no additional arguments are
passed. The latter is called to implement the deep copy operation; it
is passed one argument, the memo dictionary. If the
\method
{__
deepcopy
__
()
}
implementation needs to make a deep copy of a
component, it should call the
\function
{
deepcopy()
}
function with the
component as first argument and the memo dictionary as second
argument.
define special methods
\method
{__
copy
__
()
}
and
\method
{__
deepcopy
__
()
}
. The former is called to implement the
shallow copy operation; no additional arguments are passed. The
latter is called to implement the deep copy operation; it is passed
one argument, the memo dictionary. If the
\method
{__
deepcopy
__
()
}
implementation needs to make a deep copy of a component, it should
call the
\function
{
deepcopy()
}
function with the component as first
argument and the memo dictionary as second argument.
\withsubitem
{
(copy protocol)
}{
%
\ttindex
{__
copy
__
()
}
%
\ttindex
{__
deepcopy
__
()
}}
\begin{seealso}
\seemodule
{
pickle
}{
Discussion of the special disciplines used to
support object state retrieval and restoration.
}
\end{seealso}
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