[Python-Dev] PEP 246: lossless and stateless

Alex Martelli aleax at aleax.it
Sun Jan 16 09:23:26 CET 2005


On 2005 Jan 16, at 03:17, Phillip J. Eby wrote:
    ...
> Uh oh.  I just used "view" to describe an iterator as a view on an 
> iterable, as distinct from an adapter that adapts a sequence so that 
> it's iterable.  :)
>
> I.e., using "view" in the MVC sense where a given Model might have 
> multiple independent Views.

I think that in order to do that you need to draw a distinction between 
two categories of iterables: so, again, a problem of terminology, but 
one connected to a conceptual difference.

An iterator IS-AN iterable: it has __iter__.  However, it can't have 
"multiple independent views"... except maybe if you use itertools.tee 
for that purpose.

Other iterables are, well, ``re-iterables'': each call to their 
__iter__ makes a new fresh iterator, and using that iterator won't 
alter the iterable's state.  In this case, viewing multiple iterators 
on the same re-iterables as akin to views on a model seems quite OK.

I can't think of any 3rd case -- an iterable that's not an iterator 
(__iter__ does not return self) but neither is it seamlessly 
re-iterable.  Perhaps the ``file'' built-in type as it was in 2.2 
suffered that problem, but it was a design problem, and is now fixed.


Alex



More information about the Python-Dev mailing list