Create instance given its type
Hello
I want to create an instance given its type object. I expected that calling the type would be enough, something like this:
obj = (MyFooObject *) PyObject_CallFunctionObjArgs(&MyFooType, other, arguments, NULL)
but it doesn't work (nor even compiles, I think). So this is what I'm doing now:
obj = (MyFooObject *) PyObject_CallMethod((PyObject *)&PyType_Type, "__call__", "OOO", &MyFooType, other, arguments);
where MyFooType is a PyTypeObject struct. Ok, it works, but I'm pretty sure there is a more direct way - but how?
Thanks,
Gabriel Genellina
Yahoo! Cocina
Encontra las mejores recetas con Yahoo! Cocina.
Gabriel Genellina, 08.01.2010 17:45:
I want to create an instance given its type object. I expected that calling the type would be enough, something like this:
obj = (MyFooObject *) PyObject_CallFunctionObjArgs(&MyFooType, other, arguments, NULL)
but it doesn't work (nor even compiles, I think).
You think? Didn't you try it?
You might have to cast the type pointer to PyObject* to make it work.
Stefan
participants (2)
-
Gabriel Genellina
-
Stefan Behnel