[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: > . . . > approx *= estimate(x, iterable)
Good inspiration; wrong technique. For the RightWay(tm), try a functional approach composing a target calculation with a function generating successively more accurate approximations and a consumer function that stops when the desired accuracy is achieved. The idea is to decouple the steps into side-effect-free, reusable components. For a worked-out, comprehensive example, see http://www.md.chalmers.se/~rjmh/Papers/whyfp.pdf . > But these are highly contrived and hardly compelling. That suggests an answer to your earlier question as to whether itertools.interruptable(iterable) would be a useful addition ;-) Raymond _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com