A
Alex Martelli
Interested parties (essentially, people who write user-coded iterator, or
are intense users of iterators as "stream of data", of standard library
module itertools, etc) are welcome to read, and possibly comment on, a new
PEP on copyable iterators, see:
http://www.python.org/peps/pep-0323.html
The PEP is currently at revision 1.2, having already been amended and vastly
extended as a consequence of discussions on these issues on python-dev.
In brief, the PEP proposes that:
iterator types supply a __copy__ method, if, and only if, the method can
make an independently iterable copy of their instances at reasonably low
cost in time and memory;
the new function itertools.tee be optimized to exploit this method if its
argument iterators support it;
existing built-in iterator types be upgraded to supply this __copy__ method
where applicable;
user-written code normally rely on itertools.tee to get independently
iterable iterators on the same underlying sequence (occasionally, for
special needs, user-written code may feature-test an iterator for __copy__,
as long as said user code wants to deal directly and in special ways with
both cases, that of copyable iterators and that of non-copyable iterators).
Alex
are intense users of iterators as "stream of data", of standard library
module itertools, etc) are welcome to read, and possibly comment on, a new
PEP on copyable iterators, see:
http://www.python.org/peps/pep-0323.html
The PEP is currently at revision 1.2, having already been amended and vastly
extended as a consequence of discussions on these issues on python-dev.
In brief, the PEP proposes that:
iterator types supply a __copy__ method, if, and only if, the method can
make an independently iterable copy of their instances at reasonably low
cost in time and memory;
the new function itertools.tee be optimized to exploit this method if its
argument iterators support it;
existing built-in iterator types be upgraded to supply this __copy__ method
where applicable;
user-written code normally rely on itertools.tee to get independently
iterable iterators on the same underlying sequence (occasionally, for
special needs, user-written code may feature-test an iterator for __copy__,
as long as said user code wants to deal directly and in special ways with
both cases, that of copyable iterators and that of non-copyable iterators).
Alex