[Python-Dev] Wishlist: dowhile

Raymond Hettinger python at rcn.com
Tue Jun 14 08:25:40 CEST 2005


> def readby(inp, blocksize=1024):
>      while True:
>          data = inp.read(blocksize)
>          if not data:
>              break
>          yield data
> 
> for data in readby(inp, blocksize):
>      . . .

readby() relies on the existence of a read() method for inp. 
itertools work with generic iterators, not ones with a specific API.
Law of Demeter. 



Raymond


More information about the Python-Dev mailing list