Class and Instance Objects

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 类型对象 ).

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 在 Python 层。

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 )

返回 True 若 klass 是子类化的 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 )

返回 True 若 obj is an instance.

PyObject * PyInstance_New ( PyObject *class , PyObject *arg , PyObject *kw )
返回值:新引用。

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 )
返回值:新引用。

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__ ;若 NULL , a new dictionary will be created for the instance.

上一话题

字典对象

下一话题

函数对象

本页