Bla*_*rad 11
>>> import weakref
>>> class Object:
... pass
...
>>> o = Object()
>>> r = weakref.ref(o)
>>> # if the reference is still active, r() will be o, otherwise None
>>> do_something_with_o(r())
Run Code Online (Sandbox Code Playgroud)
有关更多详细信息,请参阅wearkref模块文档.您还可以使用weakref.proxy创建代理o的对象.ReferenceError如果在不再引用引用对象时使用将抛出.
| 归档时间: |
|
| 查看次数: |
780 次 |
| 最近记录: |