[Python-3000] iostack, second revision
jcarlson at uci.edu
Tue Sep 12 18:05:50 CEST 2006
"Anders J. Munch" <ajm at flonidan.dk> wrote:
> Greg Ewing wrote:
> > Anders J. Munch wrote:
> > > any file that supports seeking to the end will also support
> > > reporting the file size. Thus
> > > f.seek(f.length)
> > > should suffice,
> > Although the micro-optimisation circuit in my
> > brain complains that it will take 2 system
> > calls when it could be done with 1...
> I don't expect file methods and systems calls to map one to one, but
> you're right, the first time the length is needed, that's an extra
> system call.
Every time the length is needed, a system call is required (you can have
multiple writers of the same file)...
>>> import os
>>> a = open('test.txt', 'a')
>>> b = open('test.txt', 'a')
> My micro-optimisation circuitry blew a fuse when I discovered that
> seek always implies flush. You won't get good performance out of code
> that does a lot of seeks, whatever you do. Use my upcoming FileBytes
> class :)
Flushing during seek is important. By not flushing during seek in your
FileBytes object, you are unnecessarily delaying writes, which could
cause file corruption.
More information about the Python-3000