I need to convert a Python list of ints to vector[int] in a cdef function to call another C function. I tried this:
cdef pylist_to_handles(hs):
cdef vector[int] o_vect
for h in hs:
o_vect.push_back(h)
return o_vect
This should work because I only need to call this from other cdef functions, but I get this error:
Cannot convert ‘vector<int>’ to Python object
What am I doing wrong ?
What you really have is this:
If you do not explicitily set a type, it is assumed to be a python object (“object” in code). As you see in the code, you’re trying to cast vector[int] to an object, but Cython does not know how to handle that.
Just add a return type in cdef: