我在網上搜索過但沒有獲得成功。我包裝下面的示例代碼到Python(使用痛飲):在Python中製作可迭代的C++數組對象
class atomo {
public:
int i;
atomo(int a) {
i = a;
};
};
class funa {
public:
atomo *lista[3];
funa() {
lista[0] = new atomo(1);
lista[1] = new atomo(2);
lista[2] = new atomo(3);
};
};
但是Python不能超過迭代或使用該命令對應的
>>> test = myModule.funa()
>>> test.lista[0]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 6, in __iter__
TypeError: 'SwigPyObject' object is not subscriptable
>>> for i in test.lista:
>>> print(i)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 6, in __iter__
TypeError: 'SwigPyObject' object is not subscriptable
訪問lista
我怎樣才能讓lista
迭代?有一種方法可以使用Python列表而不是C++數組?
我的Python版本是3.2,我使用痛飲2.0.4使用g ++ 4.6.1
感謝
只是一個猜測:'名單(test.lista)' – rplnt 2012-01-17 15:09:27