Opening file for reading and writing

06 Apr 2010

Hello, I'm having a problem. I'm trying to open a file for reading and writing at the same time. First reading then writing doesn't work for me. Tried using 'rw' 'r+' modes but it wouldnt work - it can read the file but it cant write in it. Is there some kind of trick to it or is it just impossible ?

06 Apr 2010

Maybe try binary mode (i.e. "r+b"). Also, I found this note in the docs:

"For the modes where both read and writing (or appending) are allowed (those which include a "+" sign), the stream should be flushed (fflush) or repositioned (fseek, fsetpos, rewind) between either a reading operation followed by a writing operation or a writing operation followed by a reading operation."