proposal: another file iterator

Bengt Richter bokr at oz.net
Mon Jan 16 05:23:47 EST 2006


On 15 Jan 2006 18:58:53 -0800, Paul Rubin <http://phr.cx@NOSPAM.invalid> wrote:

>Jean-Paul Calderone <exarkun at divmod.com> writes:
>> 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.
>
>Well, iter could be extended to take *args and **kwargs parameters, so
>you'd say
>
>    for chunk in iter(f.read, '', (blocksize,)): ...
>
Whatever "Which" refers to got snipped or may be in a post that hasn't
become visible for me yet, but I assume Jean-Paul was referring to lambda use
as in e.g. (untested):

     for chunk in iter(lambda frd=open('yerf', 'rb').read:frd(blocksize), ''): ...

Does it not do what you want?

Regards,
Bengt Richter



More information about the Python-list mailing list