[Python-Dev] Single- vs. Multi-pass iterability

Andrew Koenig ark@research.att.com
Thu, 11 Jul 2002 12:16:15 -0400 (EDT)


David> Why bother with __multiter__? If you can distinguish a multiple
David> iterator by the presence of __copy__, You can always do
David> hasattr(x.__iter__(),"__copy__") to find out whether something
David> is multi-iteratable.

Because explicit is better than implicit :-)

More seriously, I can imagine distinguishing a multiple iterator by
the presence of __copy__, but I can't imagine using the presence of
__copy__ to determine whether a *container* supports multiple
iteration.  For example, there surely exist containers today that
support __copy__ but whose __iter__ methods yield iterators that do
not themselves support __copy__.

Another reason is that I can imagine this idea extended to encompass,
say, ambidextrous iterators that support prev() as well as next(),
and I would want to use __ambiter__ as a marker for those rather
than having to create an iterator and see if it has prev().