Josh Rosenberg added the comment:

+1; I've had several cases where I'd have used something like this (for the 
exact purpose mentioned, to destructively consume an input iterable). I don't 
think it's more or less useful than the sentinel version, which is convenient 
for iterating a file by blocks instead of by line, e.g.:

from functools import partial

with open('...', 'rb') as f:
    for block in iter(partial(f.read, 4096), b''):
        ...

But it would still nice to be able to destructively iterate sequences, 
particularly in CPython, where doing it at the C level can get you atomicity 
without relying on anything beyond the GIL (and without wrapping infinite while 
loops in try/except: pass blocks, which is pointlessly verbose).

One issue: You can't just make the second argument allow exception types as 
well, since it's possible (however unlikely) for an exception type to be a 
legitimate return type from a function. Making it keyword only would solve that 
problem though.

----------
nosy: +josh.rosenberg

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue20663>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to