Raising Python exception
Gaetan Corneau
Gaetan_Corneau at baan.com
Mon May 10 11:06:37 EDT 1999
I think my original message didn't reach the list, so here it is again:
I'm using SWIG to wrap C++ STL vector and I want to be able to write the
following in my Python scripts:
sv = StringVector() # vector<string>
for s in sv: print s
So, I wrote the following in my SWIG interface file:
struct StringVector{
StringVector();
%addmethods {
char* __getitem__(int i) {
if (i < self->size()) {
return (char *)((*self)[i].c_str());
} else {
PyErr_SetString(PyExc_IndexError, "index out-of-bounds");
return NULL;
}
}
}
};
The problem is that no exception is ever raised when sv[i] is out of bounds.
What's missing?
TIA,
______________________________________________________
Gaetan Corneau
Software Developer (System integration Team)
BaaN Supply Chain Solutions
E-mail: Gaetan_Corneau at baan.com
Compuserve: Gaetan_Corneau at compuserve.com
ICQ Number: 7395494
Tel: (418) 654-1454 ext. 252
______________________________________________________
"Profanity is the one language all programmers know best"
More information about the Python-list
mailing list