[Python-Dev] Single- vs. Multi-pass iterability
Moore, Paul
Paul.Moore@atosorigin.com
Tue, 9 Jul 2002 09:57:35 +0100
IIRC from earlier discussions on the list, iterators "by design" do not
expose this information. In C++ terms, all Python iterators are forward
iterators (I could argue here that it's the C++ usage of the word "iterator"
for something that "points" and often does more than just "iterate" that is
misleading, but that's off topic).
If you need to know more than that, I think that the design intent is that
you pass the *container* around, and get at the iterator via
iter(container). Of course, this sort of begs the question as to how you can
introspect a container, to determine what properties its iterators can have
(but lets not go there - I can see Alex Martelli popping up to claim that
the adaption PEP will let you do that :-)). But you do have a better chance,
by requiring that the container support a richer interface, or just by type
testing.
Paul.