Newbie - How to iterate list or scalar ?

Terry Reedy tjreedy at udel.edu
Tue Aug 8 16:02:47 EDT 2006


"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.  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 ;-)

>Fact is that Python is not exactly a
> newborn language (first release was around 1990 IIRC), and it has
> greatly evolved over the year. The BDFL being very conservative, great
> cares have been taken to ensure compatibility with older versions - with
> the side effect that there are lots of stuff that now looks like warts
> or inconsistencies. The 3K release is supposed to be the big cleanup,
> but until then, we'll have to live with all the compat stuff.

I am sure the support for iteration via __getitem__ will disappear in 3.0.

Terry Jan Reedy









More information about the Python-list mailing list