PyDocs

Nav

Data Types

ref

weakref

class
  • ref(object[, callback])
Return a weak reference to object. The original object can be retrieved by calling the reference object if the referent is still alive; if the referent is no longer alive, calling the reference object will cause None to be returned. If callback is provided and not None, and the returned weakref object is still alive, the callback will be called when the object is about to be finalized; the weak reference object will be passed as the only parameter to the callback; the referent will no longer be available.
Changed in 3.4
  • 3.4: Added the __callback__ attribute.
Members of ref

_

__callback__
This read-only attribute returns the callback currently associated to the weakref.
1 Example
>>> import weakref
>>> class Object:
...     pass
...
>>> o = Object()
>>> r = weakref.ref(o)
>>> o2 = r()
>>> o is o2
True
from the Python docs
See Also
No see-alsos for weakref/ref
0 Notes
No notes for ref