Newbie question: files
Niels Diepeveen
niels at endea.demon.nl
Sun May 14 14:52:39 EDT 2000
William Wallace schreef:
>
> I open a file "a+"
>
> fd = open(foo, "a+")
>
> I write some lines to it, taking care to flush after each write. I
> read some previously written lines by seeking back to them.
>
> However, when I seek back to a previously written line, I cannot
> update any part of the line. The updates get written to the end of the
> file regardless of current position (known from fd.tell()).
>
> What's up?
You asked for append mode, and you got it. If you don't want that, you
could do something like
open(foo, 'a').close() # make sure the file exists, but don't destroy
it
fd = open(foo, 'r+') # open existing file for read/write
fd.seek(0, 2) # seek to end of file
--
Niels Diepeveen
Endea automatisering
More information about the Python-list
mailing list