1

I want to call a function of static PyObject type which I described inside my c program in the inside of that that c program. How to call this function? What will be the (Pyobject self) argument? I understand that the "args" argument will be any module name.

I have tried calling mynewfunction("",Pfunc). Here my mynewfunction is defined as static PyObject mynewfunction(Pyobject *self, PyObject *args). But it did not work. How to call this function from inside of C after PyInitialize()? What I will put in place of *self?

#include <Python.h>
 static PyObject *string_arr_conversion(PyObject *self, PyObject args){
     Pyobject *str_arr;
     int i;
     .......
     .......
 }
 int main(int argc,char *argv[]){
     ............
     ............
     Py_Initialize();
     .............
     string_arr_conversion("",pFunc);
 }

here I kept the self argument empty. What we need to put in place of self argument? Or how to call this function in c ?

0

1 Answer 1

1

Since this appears to be a function and not a method, since it does not belong to a class, you would use NULL for self. So calling the function with something like

 string_arr_conversion(NULL, pFunc);

is what you are looking for.

Sign up to request clarification or add additional context in comments.

1 Comment

I tried to call by using the above format but still I not getting my desired result. I checked before passing that is pFunc is NULL or not i saw it is not NULL. But if you see my class defination it is going inside of this if block.if(!PyArg_ParseTuple(args, "o", &str_arr)) { retun NULL; }.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.