用法:
class weakref.WeakMethod(method)
一個自定義
ref
子類,它模擬對綁定方法的弱引用(即,在類上定義並在實例上查找的方法)。由於綁定方法是短暫的,標準的弱引用無法保持它。WeakMethod
有特殊代碼來重新創建綁定方法,直到對象或原始函數死亡:>>> class C: ... def method(self): ... print("method called!") ... >>> c = C() >>> r = weakref.ref(c.method) >>> r() >>> r = weakref.WeakMethod(c.method) >>> r() <bound method C.method of <__main__.C object at 0x7fc859830220>> >>> r()() method called! >>> del c >>> gc.collect() 0 >>> r() >>>
3.4 版中的新函數。
相關用法
- Python wsgiref.simple_server.make_server用法及代碼示例
- Python wsgiref.util.FileWrapper用法及代碼示例
- Python wsgiref.util.setup_testing_defaults用法及代碼示例
- Python OpenCV waitKeyEx()用法及代碼示例
- Python winsound.SND_ALIAS用法及代碼示例
- Python wsgiref.validate.validator用法及代碼示例
- Python OpenCV waitKey()用法及代碼示例
- Python cudf.core.column.string.StringMethods.is_vowel用法及代碼示例
- Python torch.distributed.rpc.rpc_async用法及代碼示例
- Python torch.nn.InstanceNorm3d用法及代碼示例
- Python sklearn.cluster.MiniBatchKMeans用法及代碼示例
- Python pandas.arrays.IntervalArray.is_empty用法及代碼示例
- Python tf.compat.v1.distributions.Multinomial.stddev用法及代碼示例
- Python numpy.less()用法及代碼示例
- Python tf.compat.v1.distribute.MirroredStrategy.experimental_distribute_dataset用法及代碼示例
- Python Sympy Permutation.list()用法及代碼示例
- Python dask.dataframe.Series.apply用法及代碼示例
- Python networkx.algorithms.shortest_paths.weighted.all_pairs_dijkstra_path用法及代碼示例
- Python scipy.ndimage.binary_opening用法及代碼示例
- Python pyspark.pandas.Series.dropna用法及代碼示例
注:本文由純淨天空篩選整理自python.org大神的英文原創作品 weakref.WeakMethod。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。