Python/C API Inheritance

Евгений Почитаев develsoftware at gmail.com
Wed Feb 2 18:21:40 CET 2011


Hi to all.
May be someone do class inheritance in Python/C API, I know how create
superclass/subclass. But how I can initialize superclass from subclass
initializer?

struct SuperClass {
    PyObject_HEAD;
    //...
};

struct SubClass {
    PyObject_HEAD;
    //...
};

static int SubClassInit(SubClass *self, PyObject *args, PyObject
*kwds)
{
    // how I should initialize super class?
}

PyTypeObject SuperClassType = {
   //...
};

PyTypeObject SubClassType = {
	PyObject_HEAD_INIT(NULL)
	0, /* ob_size*/
	//...
        SubClassInit, /* tp_init */
        //...
	NULL, /* tp_getset */
	&SuperClassType, /* tp_base */
	NULL, /* tp_dict */
	//...
};

Another question how I can access to superclass from subclass(I need
get access to SuperClass C struct members)?

Thanks.



More information about the Python-list mailing list