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?
Asked
Active
Viewed 365 times
2

Kerrek SB
- 464,522
- 92
- 875
- 1,084

Ayaz Salikhov
- 171
- 1
- 12
1 Answers
2
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