PyInstance_New fails with new Python classes

Dmitri Mouromtsev dimour at mail.ru
Wed Mar 26 14:43:27 CET 2003


I have new python class derived from 'object' in my module:
class MyClass(object):
    pass

And I embed python in C++. When I'm tryig create new instance by using
PyInstance_New - function return NULL:
Py_Initialize();

PuObject *my_module = PyImport_ImportModule("MyModule");

PyObject *my_class = PyObject_GetAttrString(my_module, "MyClass");

if (!my_class)

    return;

PyObject *instance = PyInstance_New(my_class, NULL, NULL); // retuns NULL

It happen because PyClass_Check in PyInstance_New function fails with new
classes (they have type PyType_Type).
So, how can I create instances in embedded python?
Thanks
Dmirti







More information about the Python-list mailing list