[Python-3000] iostack and Oh Oh

Bill Janssen janssen at parc.com
Thu Nov 30 03:38:18 CET 2006


Greg Ewing wrote:

> Bill Janssen wrote:
> 
> > Incidentally, what kind of iteration should apply to files opened in
> > "binary" mode 
> 
> I don't think binary files should directly support
> iteration at all. Wrap it in an object that iterates
> the way you want.
> 
>    for b in readbytes(f):
>      ...
> 
>    for blk in readblocks(f, 1024):
>      ...
> 
> I'm inclined to think that text files shouldn't be
> directly iterable either, and you should use
> 
>    for line in readlines(f):
>      ...

I like both these ideas.  So file.readlines() would return an
iterable, then?

Bill


More information about the Python-3000 mailing list