1

I wrote a C application which uses some python code, wrapped in cython, to simplify some stuffs.
What I want to do is to return an array from a python function, callable in C.

main.c

PyImport_AppendInittab("wrapper", PyInit_libwrapper);
Py_Initialize();
PyObject *module = PyImport_ImportModule("wrapper");

char *names[] = get_names();

Py_Finalize();

wrapper.pyx

cdef public void get_names():
    names = []
    names.append('ABCD')
    names.append('1234')
    names.append('abcd')

    return names
    return names_size


Is it possible to return an array, of chars* in that case?
To handle the array in C I also need to have its size, but I can't pass an int size by reference.
What's the best way to handle this?

user10207893
  • 243
  • 1
  • 2
  • 11
  • 1
    Maybe this is your answer: https://stackoverflow.com/questions/30720121/return-an-array-from-python-to-c – Behnam Arazkhani Mar 05 '20 at 18:15
  • 1
    Your python construct is a list of strings. What exactly would be the `c` equivalent? Python strings are unicode. And a list contains pointers/references to those strings, not the strings themselves. Usually when working with Python and cython, `array` refers to a `numpy` `ndarray`, which is different from a Python list. – hpaulj Mar 05 '20 at 18:17

0 Answers0