[Python-ideas] An ABC representing "Iterable, Sized, Container"

Guido van Rossum gvanrossum at gmail.com
Sat Jul 23 20:15:32 EDT 2016


Does it work? For what categories of iterators? Surely not for streams...

--Guido (mobile)

On Jul 23, 2016 4:49 PM, "Chris Angelico" <rosuav at gmail.com> wrote:

> On Sun, Jul 24, 2016 at 2:57 AM, Serhiy Storchaka <storchaka at gmail.com>
> wrote:
> > On 22.07.16 18:48, Chris Angelico wrote:
> >>
> >> On Sat, Jul 23, 2016 at 12:20 AM, Daniel Moisset
> >> <dmoisset at machinalis.com> wrote:
> >>>
> >>> Would there be interest in some kind of method/API for restarting
> >>> iterators?
> >>> If there was a it.restart() (or reset(it)), it would probably be a good
> >>> idea
> >>> to name the concept in the same way as the method ( "Restartable" or
> >>> "Resettable"). And having that as an actual protocol would simplify the
> >>> discussion on both what the type should contain and how it should be
> >>> named,
> >>> while having actal applications to simplify code (and reduce memory
> usage
> >>> in
> >>> cases when creating a list is not needed, just making multiple passes).
> >>
> >>
> >> IMO, no. Some iterators can be restarted by going back to the original
> >> iterable and requesting another iterator, but with no guarantee that
> >> it will result in the exact same sequence (eg dict/set iterators).
> >> Does that count as restarting? And what if you start by consuming a
> >> header or two, then pass the resulting iterator to another function.
> >> Based on type, it would be restartable (say it's a list_iterator), but
> >> the called function would be highly surprised to suddenly get back
> >> more results.
> >>
> >> What you might be looking at is a protocol for "bookmarking" or
> >> "forking" an iterator. That might be more useful.
> >
> >
> > There is such a protocol. Use copy.copy().
>
> Time machine strikes again! Restarting of iterators exists.
>
> ChrisA
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160723/2849f082/attachment.html>


More information about the Python-ideas mailing list