[Python-Dev] Single- vs. Multi-pass iterability
Greg Ewing
greg@cosc.canterbury.ac.nz
Tue, 09 Jul 2002 17:51:42 +1200 (NZST)
> Imagine an altenative universe where a south african programmer called
> Rossu van Guidom writes a wonderful language called Mamba and in that
> language iterator semantics are defined like this:
>
> * Objects that wish to be iterable define an __iter__() method returning an
> iterator.
>
> * An iterator is an object with a next() method. That's all.
But that doesn't allow for things like file objects, which,
although not iterators themselves, are capable of producing
iterators of different sorts which iterate over them in
different ways -- and yet they can only be iterated over
once.
In other words, there are such things as one-shot
iterables, even if iterables and iterators are kept
separate.
Maybe a one-shot iterable should raise an exception
if you try to obtain a second iterator from it?
Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury, | A citizen of NewZealandCorp, a |
Christchurch, New Zealand | wholly-owned subsidiary of USA Inc. |
greg@cosc.canterbury.ac.nz +--------------------------------------+