Ayaz Salikhov Ayaz Salikhov - 1 year ago 209
C++ Question

Wrapping method returning c++ std::array<std::string, 4> in cython

My method returns

std::array<std::string, 4>
in C++ code. I wrap this code using Cython. I tried to wrap array using memory views. But the result is
Invalid base type for memoryview slice: string
. So can I wrap my
std::array<std::string, 4>
to use it in python like list of strs?

Answer Source

The easiest way is probably just to copy to a Python list.

For the sake of this answer I'm assuming you've wrapped your array similar to this answer and called it arrstr4. The code then looks something like:

def f():
    cdef arrstr4 res = your_cplus_plus_function()
    py_res = []
    for i in range(4):
        py_res.append(res[i]) # take advantage of autoconversion to python string
    return py_res
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download