Weak Proxies

Weak proxy

  • A wrapper around a weakly referenced instance
     >>> import weakref
     >>> import UserDict
     >>> d = UserDict.UserDict()
     >>> wd = weakref.proxy(d)
     >>> wd["spam"] = "eggs"
     >>> wd["michael"] = "ellis"
     >>> del d
     >>> wd["spanish"] = "inquisition"
     Traceback (most recent call last):
       File "", line 1, in ?
     weakref.ReferenceError: weakly-referenced object no longer exists  
     >>>
     
<<< O'Reilly OSCON 2001, New Features in Python 2, Slide 42
July 26, 2001, beazley@cs.uchicago.edu
>>>