[Python-3000] iostack and Oh Oh

Greg Ewing greg.ewing at canterbury.ac.nz
Thu Nov 30 01:34:16 CET 2006


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 can appreciate that some people might consider
practicality to beat purity here, though.

 > How about 80-byte "records" :-?

No problem:

   for card in readblocks(f, 80):
     fortran_compiler.eat(card)

:-)

--
Greg


More information about the Python-3000 mailing list