Re: [Python-Dev] Short-circuiting iterators

2005-12-07 Thread Raymond Hettinger
[Matthew F. Barnes] > The ability to remotely terminate a for-loop also struck me as somewhat > interesting: > > def estimate(item, iterable): > . . . > if good_enough: > iterable.stop() > return result > > for x in iterable: > . . . >

Re: [Python-Dev] Short-circuiting iterators

2005-12-07 Thread Matthew F. Barnes
On Tue, 2005-12-06 at 19:58 -0500, Raymond Hettinger wrote: > Any real-world use cases or compelling contrived examples? > > ISTM, that the code calling it.stop() would already be in position to > break-out of the iteration directly or set a termination flag. Instead > of: > > it = itertools

Re: [Python-Dev] Short-circuiting iterators

2005-12-06 Thread Simon Wittber
On 12/7/05, Raymond Hettinger <[EMAIL PROTECTED]> wrote: > Are there any generator specific needs that are not met by the PEP 342 > implementation? Given a choice between throw(), close(), and send(), I > would have thought that all the bases have been covered. Agreed. When the new functionality

Re: [Python-Dev] Short-circuiting iterators

2005-12-06 Thread Raymond Hettinger
[Matthew F. Barnes] > > > Perhaps it would be a useful addition to the itertools > > > module then? > > > > > > itertools.interruptable(iterable) [Raymond Hettinger] > > Any real-world use cases or compelling contrived examples? [Simon Wittber] > I use something like this in the nanothr

Re: [Python-Dev] Short-circuiting iterators

2005-12-06 Thread Simon Wittber
On 12/7/05, Raymond Hettinger <[EMAIL PROTECTED]> wrote: > [Matthew F. Barnes] Perhaps it would be a useful addition to the > itertools > > module then? > > > > itertools.interruptable(iterable) > > Any real-world use cases or compelling contrived examples? I use something like this in th

Re: [Python-Dev] Short-circuiting iterators

2005-12-06 Thread Raymond Hettinger
[Matthew F. Barnes] Perhaps it would be a useful addition to the itertools > module then? > > itertools.interruptable(iterable) Any real-world use cases or compelling contrived examples? ISTM, that the code calling it.stop() would already be in position to break-out of the iteration dir

Re: [Python-Dev] Short-circuiting iterators

2005-11-30 Thread Matthew F. Barnes
On Wed, 2005-11-30 at 14:36 -0500, Edward Loper wrote: > There's no need to change the iterator protocol for your example use > case; you could just define a simple iterator-wrapper: Good point. Perhaps it would be a useful addition to the itertools module then? itertools.interruptable(

Re: [Python-Dev] Short-circuiting iterators

2005-11-30 Thread Edward Loper
> I had an idea this morning for a simple extension to Python's iterator > protocol that would allow the user to force an iterator to raise > StopIteration on the next call to next(). My thought was to add a new > method to iterators called stop(). There's no need to change the iterator protocol

Re: [Python-Dev] Short-circuiting iterators

2005-11-30 Thread Matthew F. Barnes
On Wed, 2005-11-30 at 10:57 -0800, Alex Martelli wrote: > PEP 342, already accepted and found at > http://python.org/peps/pep-0342.html , covers related functionality > (as well as many other points). Thanks Alex, I'll take another look at that PEP. The first time I tried to read it my brain star

Re: [Python-Dev] Short-circuiting iterators

2005-11-30 Thread Alex Martelli
On 11/30/05, Matthew F. Barnes <[EMAIL PROTECTED]> wrote: ... > I'm curious if anything like this has been proposed in the past. If so, > could someone kindly point me to any relevant mailing list threads? PEP 342, already accepted and found at http://python.org/peps/pep-0342.html , covers rel

[Python-Dev] Short-circuiting iterators

2005-11-30 Thread Matthew F. Barnes
Hello, I've not had much luck in searching for a discussion on this in the Python-Dev archives, so bear with me. I had an idea this morning for a simple extension to Python's iterator protocol that would allow the user to force an iterator to raise StopIteration on the next call to next(). My th