新聞中心
弱引用對象
python 支持 “弱引用” 作為一類對象。具體來說,有兩種直接實現(xiàn)弱引用的對象。第一種就是簡單的引用對象,第二種盡可能地作用為一個原對象的代理。

創(chuàng)新互聯(lián)主營晉中網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營網(wǎng)站建設(shè)方案,重慶APP開發(fā),晉中h5成都微信小程序搭建,晉中網(wǎng)站營銷推廣歡迎晉中等地區(qū)企業(yè)咨詢
int PyWeakref_Check(ob)
如果 ob 是一個引用或代理對象則返回真值。 此函數(shù)總是會成功執(zhí)行。
int PyWeakref_CheckRef(ob)
如果 ob 是一個引用對象則返回真值。 此函數(shù)總是會成功執(zhí)行。
int PyWeakref_CheckProxy(ob)
如果 ob 是一個代理對象則返回真值。 此函數(shù)總是會成功執(zhí)行。
PyObject *PyWeakref_NewRef(PyObject *ob, PyObject *callback)
Return value: New reference. Part of the Stable ABI.
Return a weak reference object for the object ob. This will always return a new reference, but is not guaranteed to create a new object; an existing reference object may be returned. The second parameter, callback, can be a callable object that receives notification when ob is garbage collected; it should accept a single parameter, which will be the weak reference object itself. callback may also be None or NULL. If ob is not a weakly referencable object, or if callback is not callable, None, or NULL, this will return NULL and raise TypeError.
PyObject *PyWeakref_NewProxy(PyObject *ob, PyObject *callback)
Return value: New reference. Part of the Stable ABI.
Return a weak reference proxy object for the object ob. This will always return a new reference, but is not guaranteed to create a new object; an existing proxy object may be returned. The second parameter, callback, can be a callable object that receives notification when ob is garbage collected; it should accept a single parameter, which will be the weak reference object itself. callback may also be None or NULL. If ob is not a weakly referencable object, or if callback is not callable, None, or NULL, this will return NULL and raise TypeError.
PyObject *PyWeakref_GetObject(PyObject *ref)
Return value: Borrowed reference. Part of the Stable ABI.
返回弱引用對象 ref 的被引用對象。如果被引用對象不再存在,則返回 Py_None。
備注
該函數(shù)返回被引用對象的一個 borrowed reference。 這意味著應(yīng)該總是在該對象上調(diào)用 Py_INCREF(),除非是當(dāng)它在借入引用的最后一次被使用之前無法被銷毀的時候。
PyObject *PyWeakref_GET_OBJECT(PyObject *ref)
Return value: Borrowed reference.
Similar to PyWeakref_GetObject(), but does no error checking.
文章名稱:創(chuàng)新互聯(lián)Python教程:弱引用對象
當(dāng)前網(wǎng)址:http://fisionsoft.com.cn/article/cohcgjh.html


咨詢
建站咨詢
