[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 directly or set a termination flag.  Instead
of:

    it = itertools.interruptable(iterable):
    for x in it:
        . . .
        if cond(x):
            it.stop()

Why not write:

    for x in iterable:
        . . .
        if cond(x):
            break

If needed, the for-loop can have an else-clause for any processing
needed in the event of interruption.



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

Reply via email to