[Python-ideas] should there be a difference between generators and iterators?

Bruce Frederiksen dangyogi at gmail.com
Fri Sep 5 01:01:53 CEST 2008

I guess while we're at it, I'd like to add the following to the discussion:

6.  Add the context manager methods (__enter__ and __exit__) to
generators and, by extension, to itertools.  This makes it easier to
use 'with' to get the clean up ('finally' clauses) done.

On Thu, Sep 4, 2008 at 10:58 AM, Bruce Frederiksen <dangyogi at gmail.com> wrote:
> There are several points here that might or might not be adopted
> individually.
> [...]
> I propose the following.  Each of these is independent of the others, but
> all related to cleaning up how this works:
> 1.  All of the itertools and map (and I've no doubt left some others out
> here) be extended to propagate the extra generators methods: close, throw
> and send.
> 2.  That the 'for' loop be extended so that if an exception occurs within
> its body, it calls 'throw' on its iterable (if it has a throw method).
> 3.  That the 'for' loop be extended to call the 'close' method on its
> iterable (if it has a close method) when the loop terminates (either
> normally, with break, or with an exception).
> 4.  That a 'not_closing' builtin function be added that takes an iterable
> and shields it from a 'close' call.
> 5.  That 'close' and 'throw' be added to all iterables.

More information about the Python-ideas mailing list