Movatterモバイル変換


[0]ホーム

URL:


[Python-Dev] empty string api for files

Guido van Rossumgvanrossum 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 inN-bytes chucks? I really think you've got a solution in search of aproblem by the horns here.While this would be useful for a copying loop, it falls down for mostpractical uses of reading bytes (e.g. reading GIF or WAVE file).I've thought a lot about redesigning the file/stream API, but theproblems thi API change would solve just aren't high on my list. Muchmore important are transparency of the buffering (for betterintegration with select()), and various translations like universalnewlines or character set encodings. Some of my work on this isnondist/sandbox/sio/.-- --Guido van Rossum (home page:http://www.python.org/~guido/)


More information about the Python-Devmailing list

[8]ページ先頭

©2009-2025 Movatter.jp