chuck in a jsfile.close(). The buffer isn't flushing with what you are doing now. jsfile.flush() might work... not sure. Closing and re-opening the file for sure will help though.
On Tue, Apr 29, 2008 at 1:26 AM, Kevin K <[EMAIL PROTECTED]> wrote: > 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 > -- http://mail.python.org/mailman/listinfo/python-list