Method Objects - Python 2.7.18 documentation 编辑

There are some useful functions that are useful for working with method objects.

PyTypeObject PyMethod_Type

This instance of PyTypeObject represents the Python method type. This is exposed to Python programs as types.MethodType.

int PyMethod_Check(PyObject *o)

Return true if o is a method object (has type PyMethod_Type). The parameter must not be NULL.

PyObject* PyMethod_New(PyObject *func, PyObject *self, PyObject *class)
Return value: New reference.

Return a new method object, with func being any callable object; this is the function that will be called when the method is called. If this method should be bound to an instance, self should be the instance and class should be the class of self, otherwise self should be NULL and class should be the class which provides the unbound method..

PyObject* PyMethod_Class(PyObject *meth)
Return value: Borrowed reference.

Return the class object from which the method meth was created; if this was created from an instance, it will be the class of the instance.

PyObject* PyMethod_GET_CLASS(PyObject *meth)
Return value: Borrowed reference.

Macro version of PyMethod_Class() which avoids error checking.

PyObject* PyMethod_Function(PyObject *meth)
Return value: Borrowed reference.

Return the function object associated with the method meth.

PyObject* PyMethod_GET_FUNCTION(PyObject *meth)
Return value: Borrowed reference.

Macro version of PyMethod_Function() which avoids error checking.

PyObject* PyMethod_Self(PyObject *meth)
Return value: Borrowed reference.

Return the instance associated with the method meth if it is bound, otherwise return NULL.

PyObject* PyMethod_GET_SELF(PyObject *meth)
Return value: Borrowed reference.

Macro version of PyMethod_Self() which avoids error checking.

int PyMethod_ClearFreeList()

Clear the free list. Return the total number of freed items.

New in version 2.6.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:53 次

字数:3696

最后编辑:7年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文