[PyQt] SIP - %Exception for StopIteration

Phil Thompson phil at riverbankcomputing.com
Wed Aug 6 09:13:54 BST 2008

On Tue, 5 Aug 2008 22:23:31 -0700, "Jonny Morrill" <jrmorrill at gmail.com>
> Thank you both for your help!!
> @Matt:
> WOW! I never new that you could create an iterable object from only the
> __len__ and operator[] functions!! I must have missed that when I was
> searching through the python documentation for iterator objects. It is
> clear to me which is quicker, the only difference seems to be that when
> you
> use __iter__, you can return a copy of the object so that any
> modifications
> will not affect the original object. Thanks again!
> @Giovanni:
> That seems to be exactly what I was after. I have a few questions about
> the
> implementation though.
> Since I do use the next() function as part of my C++ API i might just
> my iteration the way it is currently. I use it to iterate similar to the
> following code:
> Item* Object::next()
> {
>   if(this->currentIndex < this->length) {
>     return item[this->currentIndex];
>   } else {
>     return NULL;
>   }
> }
> // In Code
> Object* object = new Object;
> Item* item;
> while(item = object->next()) {
>   // do something with item
> }
> Oh!! So the %MethodCode doesn't require a partner C++ function? You can
> specify python specific functions inside it??


Most people probably don't realise it but you can use SIP to write new
C/C++ extension modules (as opposed to wrapping an external library). SIP
will handle all the boilerplate code, module initialisation, argument and
return value marshaling etc. You just provide the "meat" of what you want
the module to do as %MethodCode.



More information about the PyQt mailing list