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
cb839881
Commit
cb839881
authored
Mar 28, 2001
by
Fred Drake
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added example use of weak references, contributed by Tim Peters.
parent
58c8f9f6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
0 deletions
+22
-0
Doc/lib/libweakref.tex
Doc/lib/libweakref.tex
+22
-0
No files found.
Doc/lib/libweakref.tex
View file @
cb839881
...
...
@@ -181,6 +181,28 @@ idiom shown above is safe in threaded applications as well as
single-threaded applications.
\subsection
{
Example
\label
{
weakref-example
}}
This simple example shows how an application can use objects IDs to
retrieve objects that it has seen before. The IDs of the objects can
then be used in other data structures without forcing the objects to
remain alive, but the objects can still be retrieved by ID if they
do.
% Example contributed by Tim Peters <tim_one@msn.com>.
\begin{verbatim}
import weakref
_
id2obj
_
dict = weakref.mapping()
def remember(obj):
_
id2obj
_
dict[id(obj)] = obj
def id2obj(id):
return
_
id2obj
_
dict.get(id)
\end{verbatim}
\subsection
{
Weak References in Extension Types
\label
{
weakref-extension
}}
...
...
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