I have searched on the web and didn't get success. I'm wrapping the sample code below to Python (using SWIG):
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);
};
};
But Python can't iterate over or access lista
using the comands
>>> 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
How can I make lista
iterable? There is a way to use Python lists instead of C++ arrays?
My Python version is 3.2 and I'm using SWIG 2.0.4 with g++ 4.6.1
Thanks