Recursive list comprehension

Terry Reedy tjreedy at udel.edu
Wed Dec 8 19:40:36 EST 2004


"Steven Bethard" <steven.bethard at gmail.com> wrote in message 
news:o5Jtd.224974$R05.24953 at attbi_s53...
> Probably you want to catch a TypeError instead of an AttributeError; 
> objects may support the iterator protocol without defining an __iter__ 
> method:

No, having an __iter__ method that returns an iterator is an essential half 
of the current iterator protocol just so that iter(iterator) (== 
iterator.__iter__()) always works.  This requirement conveniently makes 
'iterator' a subcategory of 'iterable'.  (I am ignoing the old and obsolete 
getnext protocol, as does the itertools library module.)

Terry J. Reedy






More information about the Python-list mailing list