I have a python object called "m1", which has a method "coor()". I will pass it to C"++" extension and call "coor()" inside. First I tried:
PyArrayObject *coor = (PyArrayObject *) PyObject_CallMethod(m1,"coor","()",NULL);
and found the following awkward code works:
char t1[]="coor, t3[]="()";
PyArrayObject *coor = (PyArrayObject *) PyObject_CallMethod(m1,t1,t3,NULL);
I believe there is a easy way to do that. This maybe a C question on char[] for a beginner, and thanks for advice.
The documentation says:
Additionally, there is no need for arrays. What made you think it needed arrays is likely the fact that the strings are not declared to be constant:
However, they are not actually modified; look at the source;
method
is only passed toPyObject_GetAttrString
andPyErr_SetString
, both of which takeconst char *
s. Therefore, it should be safe to cast theconst char *
literal into achar *
, although the real solution would be for Python to change the declared parameter types toconst char *
.Anyway, with that said, this:
Would be roughly converted to this: