On this page
  1. weakref.ref
  2. Import
  3. Signature & Overview
  4. Usage
  5. Gotchas
  6. REPL Inspect

weakref.ref

Prev: weakref.ProxyType | Up: weakref | Next: weakref.ReferenceType
Rel: weakref.CallableProxyType, weakref.finalize, weakref.getweakrefcount, weakref.getweakrefs
Ref: docs.python.org — weakref.ref
Tags: #public #python3 #stdlib #weakref


Import

import weakref
from weakref import ref

Signature & Overview

weakref.ref(...)

weakref.ref class.

Usage

import weakref

class Box: pass
b = Box()
r = weakref.ref(b)
assert r() is b
del b
assert r() is None

Gotchas

REPL Inspect

from weakref import ref
help(ref)

Linked from

Related notes