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
Hide 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 @@
...
@@ -4,9 +4,9 @@
\modulesynopsis
{
Shallow and deep copy operations.
}
\modulesynopsis
{
Shallow and deep copy operations.
}
\
setindexsubitem
{
(copy function)
}
\
withsubitem
{
(in module copy)
}{
%
\ttindex
{
copy
}
\ttindex
{
copy
}
%
\ttindex
{
deepcopy
}
\ttindex
{
deepcopy
}
}
This module provides generic (shallow and deep) copying operations.
This module provides generic (shallow and deep) copying operations.
...
@@ -19,7 +19,7 @@ x = copy.copy(y) # make a shallow copy of y
...
@@ -19,7 +19,7 @@ x = copy.copy(y) # make a shallow copy of y
x = copy.deepcopy(y) # make a deep copy of y
x = copy.deepcopy(y) # make a deep copy of y
\end{verbatim}
\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
The difference between shallow and deep copying is only relevant for
compound objects (objects that contain other objects, like lists or
compound objects (objects that contain other objects, like lists or
...
@@ -49,13 +49,13 @@ Recursive objects (compound objects that, directly or indirectly,
...
@@ -49,13 +49,13 @@ Recursive objects (compound objects that, directly or indirectly,
contain a reference to themselves) may cause a recursive loop.
contain a reference to themselves) may cause a recursive loop.
\item
\item
Because deep copy copies
\emph
{
everything
}
it may copy too much,
e.g.
\
Because deep copy copies
\emph
{
everything
}
it may copy too much,
administrative data structures that should be shared even betwe
en
e.g., administrative data structures that should be shared ev
en
copies.
between
copies.
\end{itemize}
\end{itemize}
Python's
\code
{
deepcopy()
}
opera
tion avoids these problems by:
The
\function
{
deepcopy()
}
func
tion avoids these problems by:
\begin{itemize}
\begin{itemize}
...
@@ -75,24 +75,30 @@ any similar types.
...
@@ -75,24 +75,30 @@ any similar types.
Classes can use the same interfaces to control copying that they use
Classes can use the same interfaces to control copying that they use
to control pickling: they can define methods called
to control pickling: they can define methods called
\code
{__
getinitargs
__
()
}
,
\code
{__
getstate
__
()
}
and
\method
{__
getinitargs
__
()
}
,
\method
{__
getstate
__
()
}
and
\code
{__
setstate
__
()
}
. See the description of module
\code
{
pickle
}
\method
{__
setstate
__
()
}
. See the description of module
for information on these methods.
\module
{
pickle
}
\refstmodindex
{
pickle
}
for information on these
The copy module does not use the
\module
{
copy
_
reg
}
registration
methods. The
\module
{
copy
}
module does not use the
\module
{
copy
_
reg
}
module.
registration module.
\refstmodindex
{
pickle
}
\withsubitem
{
(copy protocol)
}{
%
\setindexsubitem
{
(copy protocol)
}
\ttindex
{__
getinitargs
__
()
}
%
\ttindex
{__
getinitargs
__}
\ttindex
{__
getstate
__
()
}
%
\ttindex
{__
getstate
__}
\ttindex
{__
setstate
__
()
}}
\ttindex
{__
setstate
__}
In order for a class to define its own copy implementation, it can
In order for a class to define its own copy implementation, it can
define special methods
\method
{__
copy
__
()
}
\ttindex
{__
copy
__}
and
define special methods
\method
{__
copy
__
()
}
and
\method
{__
deepcopy
__
()
}
\ttindex
{__
deepcopy
__}
. The former is called to
\method
{__
deepcopy
__
()
}
. The former is called to implement the
implement the shallow copy operation; no additional arguments are
shallow copy operation; no additional arguments are passed. The
passed. The latter is called to implement the deep copy operation; it
latter is called to implement the deep copy operation; it is passed
is passed one argument, the memo dictionary. If the
one argument, the memo dictionary. If the
\method
{__
deepcopy
__
()
}
\method
{__
deepcopy
__
()
}
implementation needs to make a deep copy of a
implementation needs to make a deep copy of a component, it should
component, it should call the
\function
{
deepcopy()
}
function with the
call the
\function
{
deepcopy()
}
function with the component as first
component as first argument and the memo dictionary as second
argument and the memo dictionary as second argument.
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