proposal: another file iterator
Benji York
benji at benjiyork.com
Sun Jan 15 21:51:07 EST 2006
Jean-Paul Calderone wrote:
> When I just want the dumb version, I tend to write this:
>
> for chunk in iter(lambda: f.read(blocksize), ''): ...
>
> Which is only very slightly longer than your version. I would like it
> even more if iter() had been written with the impending doom of lambda
> in mind, so that this would work:
>
> for chunk in iter('', f.read, blocksize): ...
>
> But it's a bit late now.
How about this instead (will work in 2.5):
for chunk in iter(partial(f.read, blocksize), ''): ...
--
Benji York
More information about the Python-list
mailing list