[PyQt] Sip iterator question

Sébastien Petitdemange sebastien.petitdemange at esrf.fr
Mon Aug 31 15:24:13 BST 2009


David Boddie wrote:
> On Mon, 24 Aug 2009 13:08:44 +0200, Sebastien Petitdemange wrote:
> 
>> Sébastien Petitdemange wrote:
> 
>>> I try to create an iterator using python iterator protocol but I didn't
>>> succeed.
> 
> [...]
> 
>>> Data_HeaderContainer_itemIterator* __iter__();
>>> %MethodCode
>>> sipRes = sipCpp;
>>> %End
>>> };
>>>
>>> and we I use it in python, It say that my object is not an iterator :
>>>
>>> for k in i:
>>> ...     print k
>>> ...
>>> Traceback (most recent call last):
>>>   File "<stdin>", line 1, in <module>
>>> TypeError: 'Data_HeaderContainer_itemIterator' object is not iterable
>>>
>>> what I'm I missing?
> 
> Maybe the value returned by __iter__() isn't what the interpreter is
> expecting. Having said that, I think it's possible that the type structure
> information created by SIP doesn't have the necessary fields filled in to
> allow the object to be used to create an iterator, even if you define
> __iter__() for this purpose.
> 
> Has anyone else encountered this problem, perhaps with tools other than SIP?
> 
> David
> 
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
> 
As a conclusion, to create an iterator in C for python, you have to
define tp_iter slot and it seems that SIP don't yet recognize __iter__
as a slot that why it doesn't work.

Hope this feature will be add to SIP!

Thanks for your replay.

SEB
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sebastien_petitdemange.vcf
Type: text/x-vcard
Size: 210 bytes
Desc: not available
Url : http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20090831/5535d3b1/sebastien_petitdemange.vcf


More information about the PyQt mailing list