我需要在 cdef 函数中将 Python 整数列表转换为 vector[int] 以调用另一个 C 函数。我试过这个:
cdef pylist_to_handles(hs):
cdef vector[int] o_vect
for h in hs:
o_vect.push_back(h)
return o_vect
这应该可以工作,因为我只需要从其他 cdef 函数调用它,但我得到了这个错误:
Cannot convert 'vector<int>' to Python object
我做错了什么?
最佳答案
在 Cython 0.17 中使用 libcpp.vector ,你可以这样做:
cdef vector[int] vect = hs
关于python - 在 Cython 中将 Python 列表转换为 Vector<int>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11454476/