[Python-Dev] empty string api for files

Raymond Hettinger raymond.hettinger at verizon.net
Sat Aug 27 17:04:54 CEST 2005


> 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.



More information about the Python-Dev mailing list