[Python-Dev] Wishlist: dowhile

Jp Calderone exarkun at divmod.com
Mon Jun 13 14:14:23 CEST 2005


On Mon, 13 Jun 2005 01:25:51 -0400, "Phillip J. Eby" <pje at telecommunity.com> wrote:
>At 09:01 PM 6/12/2005 -0700, Guido van Rossum wrote:
>>If we have to do this, PEP 315 has my +0.
>>
>>It is Pythonically minimal and the motivation rings true: I've often
>>written code like this in the past:
>>
>>     line = f.readline()
>>     while line:
>>         <do something>
>>         line = f.readline()
>>
>>But these days we do that using "for line in f".
>
>Block-copying a file with read() has the same pattern (e.g. in shutil), but
>you can't make it a for loop.

Anything can be a for loop.

  for chunk in iter(lambda: f1.read(CHUNK_SIZE), ''):
      f2.write(chunk)

Jp


More information about the Python-Dev mailing list