Reading / writing...
andrew.thompson at ashecastle.com
Thu Jan 16 14:00:21 CET 2003
Has anyone experienced a file.write() operation not actually writing
anything to a file, although the file pointer moves on... (I was
comparing prior and post seek() values to check how much data was
In the example below, the write() operation works fine if it is preceded
by a seek(), but fails if it is preceded by a read().
My original thought was that the new data simply wasn't yet flush()ed
into the file, but no amount of flush()ing can make the new data arrive
anywhere in the file.
I am aware of the importance of flush() on all reads() after writes() ,
but cannot find anything in the literature the other way around.
Can anyone help?
>>> f.write('boo') #write a simple 3 char string.
>>> f.write('a') #write a further character
>>> f.read(3) #this all works.
>>> f.write('b') #this write fails, although the file pointer moves
>>> f.read(1) #we still have the original character.
>>> f.seek(3) #trying again, but do a direct seek() first.
More information about the Python-list