웹에서 검색했지만 성공하지 못했습니다. 나는 (꿀꺽 꿀꺽 사용) 파이썬에 아래의 샘플 코드를 포장하고 있습니다 :파이썬에서 객체의 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);
};
};
그러나 파이썬은 반복 할 수 없거나 액세스 lista
이 때 명령
>>> 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
반복 가능한 만들 수 있습니까? C++ 배열 대신 파이썬 목록을 사용하는 방법이 있습니까?
내 파이썬 버전은 3.2이며, 나는 4.6.1
감사
g ++로 꿀꺽 꿀꺽 2.0.4을 사용하고
'list (test.lista)' – rplnt