[Python-Dev] RE: cloning iterators again
Alex Martelli
aleaxit at yahoo.com
Mon Oct 27 10:09:03 EST 2003
On Monday 27 October 2003 11:35 am, Armin Rigo wrote:
> Hello Alex,
>
> On Mon, Oct 27, 2003 at 08:51:02AM +0100, Alex Martelli wrote:
> > I just got a PEP number (323) for Copyable Iterators as recently
> > discussed,
>
> .. where?
I was assigned the PEP number in email today and just now committed
the PEP (and the update of PEP 0 to list it) to CVS.
> > and hope to commit the PEP within today. But, basically, the idea is
> > trivially simple: iterators which really have a tiny amount of state,
> > such as those on sequences and dicts, will expose __copy__ and implement
> > it by just duplicating said tiny amount (one pointer to a container and
> > an index).
>
> I needed this for sequence iterators and generators in a recent project.
> Duplicating a user-defined running generator seems funny, but it works
> quite well. I use this to make a snapshot of the program state and restore
> it later, and the program makes heavy use of parallel-running generators
> stored in lists.
>
> http://codespeak.net/svn/user/arigo/misc/statesaver.c
Cool! Why don't you try copy.copy on types you don't automatically
recognize and know how to deal with, BTW? That might make this
cool piece of code general enough that Guido might perhaps allow
generator-produced iterators to grow it as their __copy__ method...
Alex
More information about the Python-Dev
mailing list