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
.
Get Python in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.