On 8/27/05, Raymond Hettinger <[EMAIL PROTECTED]> 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 nondist/sandbox/sio/. -- --Guido van Rossum (home page: http://www.python.org/~guido/) _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com