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 contents of out.txt will be:
string 3
string 2
string 1
and not (like this code does):
string 1
string 2
string 3
Take a look at this question. There are some solutions there.
Though I would probably go that same way Daniel and MAK suggest — maybe make a lil’ class to make things a little more flexible and explicit: