Newbie - How to iterate list or scalar ?
Bruno Desthuilliers
onurb at xiludom.gro
Wed Aug 9 05:31:48 EDT 2006
Terry Reedy wrote:
> "Bruno Desthuilliers" <onurb at xiludom.gro> wrote in message
> news:44d8d114$0$21145$7a628cd7 at news.club-internet.fr...
>> FWIW, the iterator protocol appeared with Python 2.2. Before this
>> version, the above solution was the only one that allowed iteration over
>> a container type.
>>
>> Now if you wonder why string, unicode and buffer don't have __iter__
>> while other sequence types have it, ask your favourite Python guru (and
>> please keep me informed !-).
>
> Giving that Python still has to support the old __getitem__ protocol in for
> statements, there was no need to rewrite stuff that worked and no one did
> so for those types.
What I wonder here is why __iter__ has been added to lists and tuples
but not to strings (not that I'm complaining, it's just curiousity...)
> The emergent problem of identifying an 'iterable' had
> been noted and Guido has, I believe, approved the addition of '__iter__' to
> those types for 2.6. (But someone still has to write the patches ;-)
Which is a GoodThing(tm) wrt/ consistency - and makes clear I should not
have talked about the hasattr(obj, '__iter__') hack.
More information about the Python-list
mailing list