[PyQt] Sip iterator question
rasky at develer.com
Mon Aug 31 16:27:50 BST 2009
On 8/31/2009 4:24 PM, Sébastien Petitdemange 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
>>>> Data_HeaderContainer_itemIterator* __iter__();
>>>> sipRes = sipCpp;
>>>> 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?
> 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.
Remember that many containers are already iterable just because they
support operator (aka __getitem__). So if you have a container, it's
sufficient to expose __getitem__ (which is probably a good idea anyway)
to make it iterable.
More information about the PyQt