2008-09-08 9 views

答えて

10
>>> 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()) 

詳細はwearkref module docsを参照してください。 weakref.proxyを使用して、oをプロキシするオブジェクトを作成することもできます。指示対象が参照されなくなったときに使用される場合は、ReferenceErrorを投げます。

関連する問題