[C++-sig] call python iterable (handle StopIteration?)
Neal Becker
ndbecker2 at gmail.com
Tue Jul 17 16:31:43 CEST 2007
Stefan Seefeld wrote:
> Neal Becker wrote:
>
>> Interestingly, this _seems_ to work:
>>
>> try {
>> while (true) {
>> o.attr ("next")()...
>> }
>> }
>> catch (error_already_set) {
>> use result..
>> }
>
> Yes, it should. Though you will also break out of the loop for other
> exceptions (which you may want to deal with within the loop...).
>
> Regards,
> Stefan
>
Maybe like this?
try {
while (true) {
T n = extract<T> (o.attr ("next")());
tmp.push_back (n);
}
}
catch (error_already_set) {
if (!PyErr_ExceptionMatches (PyExc_StopIteration))
throw_error_already_set();
...
}
More information about the Cplusplus-sig
mailing list