實(shí)例方法對象?
實(shí)例方法是 PyCFunction
的包裝器,也是將 PyCFunction
綁定到類(lèi)對象的一種新方式。 它替代了原先的調用 PyMethod_New(func, NULL, class)
。
-
PyTypeObject PyInstanceMethod_Type?
這個(gè)
PyTypeObject
實(shí)例代表 Python 實(shí)例方法類(lèi)型。 它并不對 Python 程序公開(kāi)。
-
int PyInstanceMethod_Check(PyObject *o)?
如果 o 是一個(gè)實(shí)例方法對象 (類(lèi)型為
PyInstanceMethod_Type
) 則返回真值。 形參必須不為NULL
。 此函數總是會(huì )成功執行。
-
PyObject *PyInstanceMethod_New(PyObject *func)?
- Return value: New reference.
Return a new instance method object, with func being any callable object. func is the function that will be called when the instance method is called.
-
PyObject *PyInstanceMethod_Function(PyObject *im)?
- Return value: Borrowed reference.
返回關(guān)聯(lián)到實(shí)例方法 im 的函數對象。
-
PyObject *PyInstanceMethod_GET_FUNCTION(PyObject *im)?
- Return value: Borrowed reference.
宏版本的
PyInstanceMethod_Function()
,略去了錯誤檢測。
方法對象?
方法是綁定的函數對象。 方法總是會(huì )被綁定到一個(gè)用戶(hù)自定義類(lèi)的實(shí)例。 未綁定方法(綁定到一個(gè)類(lèi)的方法)已不再可用。
-
PyTypeObject PyMethod_Type?
這個(gè)
PyTypeObject
實(shí)例代表 Python 方法類(lèi)型。 它作為types.MethodType
向 Python 程序公開(kāi)。
-
int PyMethod_Check(PyObject *o)?
如果 o 是一個(gè)方法對象 (類(lèi)型為
PyMethod_Type
) 則返回真值。 形參必須不為NULL
。 此函數總是會(huì )成功執行。
-
PyObject *PyMethod_New(PyObject *func, PyObject *self)?
- Return value: New reference.
返回一個(gè)新的方法對象,func 應為任意可調用對象,self 為該方法應綁定的實(shí)例。 在方法被調用時(shí) func 將作為函數被調用。 self 必須不為
NULL
。
-
PyObject *PyMethod_Function(PyObject *meth)?
- Return value: Borrowed reference.
返回關(guān)聯(lián)到方法 meth 的函數對象。
-
PyObject *PyMethod_GET_FUNCTION(PyObject *meth)?
- Return value: Borrowed reference.
宏版本的
PyMethod_Function()
,略去了錯誤檢測。
-
PyObject *PyMethod_Self(PyObject *meth)?
- Return value: Borrowed reference.
返回關(guān)聯(lián)到方法 meth 的實(shí)例。
-
PyObject *PyMethod_GET_SELF(PyObject *meth)?
- Return value: Borrowed reference.
宏版本的
PyMethod_Self()
,略去了錯誤檢測。