Name
ref
Synopsis
ref(x[,f])
Returns a weak reference w of type
ReferenceType, with object
x as the target.
w is callable: calling
w
( ) returns
x if x is still
alive, otherwise w
( )
returns None. w is
hashable if x is hashable. You can compare
weak references for equality (= =,
!=), but not for order (<,
>, <=,
>=). Two weak references
x and y are
equal if their targets are alive and equal, or if
x
is
y. If f is
present, it must be callable with one argument, and is the
finalization callback for w (i.e., right
before finalizing x, Python calls
f
(
w
)).
Note that when f is called,
x is no longer reachable from
w.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access