[Python-Dev] bool(iter([])) changed between 2.3 and 2.4
Guido van Rossum
guido at python.org
Thu Sep 22 17:23:19 CEST 2005
On 9/22/05, Jim Jewett <jimjjewett at gmail.com> wrote:
> "Is there anything left?" is a pretty analogy for iterators,
But unmaintainable for iterators in general. This was considered ad
nauseam when iterators were initially introduced, and it was an
explicit decision *not* to provide an API to look ahead.
We should *not* give people a way to start coding like this:
while it:
x = it.next()
...process x...
when they should be writing this instead:
for x in it:
...process x...
How would you implement the "is there anything left" functionality if
the iterator is in fact a generator? (I know, the answer is buffering.
But that has problems too. It was all considered when we designed it.)
--
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-Dev
mailing list