[PyQt] Sip iterator question
Phil Thompson
phil at riverbankcomputing.com
Tue Sep 1 13:01:14 BST 2009
On Mon, 31 Aug 2009 16:24:13 +0200, Sébastien Petitdemange
<sebastien.petitdemange at esrf.fr> wrote:
> 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!
Tonight's snapshot will have support for __iter__ and __next__.
Note that it's __next__ (and not next) even for Python v2.
Phil
More information about the PyQt
mailing list