[Python-Dev] empty string api for files

Guido van Rossum gvanrossum at gmail.com
Sat Aug 27 23:54:13 CEST 2005

On 8/27/05, Raymond Hettinger <raymond.hettinger at verizon.net> wrote:
> > For reading bytes, I *know* that a lot of code would become uglier if
> > the API changed to raise EOFError exceptions
> I had StopIteration in mind.  Instead of writing:
>     while 1:
>         block = f.read(20)
>         if line == '':
>             break
>         . . .
> We would use:
>     for block in f.readblocks(20):
>         . . .
> More beauty, a little faster, more concise, and less error-prone.  Of
> course, there are likely better choices for the method name, but you get
> the gist of it.

I'm not convinced. Where would you ever care about reading a file in
N-bytes chucks? I really think you've got a solution in search of a
problem by the horns here.

While this would be useful for a copying loop, it falls down for most
practical uses of reading bytes (e.g. reading GIF or WAVE file).

I've thought a lot about redesigning the file/stream API, but the
problems thi API change would solve just aren't high on my list. Much
more important are transparency of the buffering (for better
integration with select()), and various translations like universal
newlines or character set encodings. Some of my work on this is

--Guido van Rossum (home page: http://www.python.org/~guido/)

More information about the Python-Dev mailing list