我正在开发一个C++/Python库项目,使用SWIG将C++代码转换为Python库。在其中一个C++头文件中,我有一些全局常量值如下。
const int V0 = 0;
const int V1 = 1;
const int V2 = 2;
const int V3 = 3;
const int V[4] = {V0, V1, V2, V3};
我可以直接从Python使用V0到V3,但无法访问V
中的条目。
>>> import mylibrary
>>> mylibrary.V0
0
>>> mylibrary.V[0]
<Swig Object of type 'int *' at 0x109c8ab70>
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'SwigPyObject' object has no attribute '__getitem__'
请问有人知道如何自动将 V
转换成 Python 的元组或列表吗?我应该在我的 .i
文件中做什么?