Class and Instance Objects - Python 2.7.18 documentation 编辑

Note that the class objects described here represent old-style classes, which will go away in Python 3. When creating new types for extension modules, you will want to work with type objects (section Type Objects).

PyClassObject

The C structure of the objects used to describe built-in classes.

PyObject* PyClass_Type

This is the type object for class objects; it is the same object as types.ClassType in the Python layer.

int PyClass_Check(PyObject *o)

Return true if the object o is a class object, including instances of types derived from the standard class object. Return false in all other cases.

int PyClass_IsSubclass(PyObject *klass, PyObject *base)

Return true if klass is a subclass of base. Return false in all other cases.

There are very few functions specific to instance objects.

PyTypeObject PyInstance_Type

Type object for class instances.

int PyInstance_Check(PyObject *obj)

Return true if obj is an instance.

PyObject* PyInstance_New(PyObject *class, PyObject *arg, PyObject *kw)
Return value: New reference.

Create a new instance of a specific class. The parameters arg and kw are used as the positional and keyword parameters to the object’s constructor.

PyObject* PyInstance_NewRaw(PyObject *class, PyObject *dict)
Return value: New reference.

Create a new instance of a specific class without calling its constructor. class is the class of new object. The dict parameter will be used as the object’s __dict__; if NULL, a new dictionary will be created for the instance.

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

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

发布评论

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

词条统计

浏览:20 次

字数:2910

最后编辑:8年前

编辑次数:0 次

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