Reading / writing...

Andrew Thompson andrew.thompson at
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=open('test','wb+')
>>> f.write('boo')     #write a simple 3 char string.
>>> f.tell()
>>> f.write('a')       #write a further character
>>>      #this all works.
>>> f.write('b')   #this write fails, although the file pointer moves
>>>       #we still have the original character.
>>>       #trying again, but do a direct seek() first.
>>> f.write('b')

More information about the Python-list mailing list