Python f.write() at beginning of file?

Posted by kristus on Stack Overflow See other posts from Stack Overflow or by kristus
Published on 2010-04-20T18:25:46Z Indexed on 2010/04/20 18:33 UTC
Read the original article Hit count: 211

Filed under:
|
|

I'm doing it like this now, but i want it to write at the beginning of the file instead.

f = open('out.txt', 'a') # or 'w'?
f.write("string 1")
f.write("string 2")
f.write("string 3")
f.close()

so that the contenst of out.txt will be:

string 3
string 2
string 1

and not (like this code does):

string 1
string 2
string 3

© Stack Overflow or respective owner

Related posts about python

Related posts about file-io