[Python-Dev] The iterator story

Oren Tirosh oren-py-d@hishome.net
Sat, 20 Jul 2002 08:58:51 -0400


> >     Based on Guido's positive response, in which he asked me to make
> >     an addition to the PEP, i believe Guido agrees with me that
> >     __iter__ is distinct from the protocol of an iterator.  This
> >     surprised me because it runs counter to the philosophy previously
> >     expressed in the PEP.
> 
> I recognize that they are separate protocols.  But because I like the
> for-loop as a convenient way to get all of the elements of an
> iterator, I want iterators to support __iter__.

Is this the only reason iterators are required to support __iter__?

It seems like a strange design decision to put the burden on all iterator 
implementers to write a dummy method returning self instead of just checking 
if tp_iter==NULL in PyObject_GetIter. It's like requiring all class writers 
to write a dummy __str__ method that calls __repr__ instead of implementing 
the automatic fallback to __repr__ in PyObject_Str when no __str__ is 
available.

	Oren