Hey everyone, I'm new to python and am trying to do a little project
with it. I'm running into problems writing over a file. I read from
the file and loop through for a specfic case in which I change
something. After I open and give it opening options (w, r, etc) one of
two things happens: either the file gets truncated and my writing
never takes place (or it seems it doesnt) or everything is appended to
the file and I have a double of what I started with, its never just
the updated file. Can someone shed some light on this for me?? Code
below:

jsfile = open("../timeline.js", "r+")
jscontent = jsfile.readlines()
jsfile.truncate()

for line in jscontent:
        if re.search('var d =', line):
                line = "var d = \""+mint['1'].ascdate()+"\"\n"
                print line
        jsfile.write(line)
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to