File IO Issues, help :(
Eric Wertman
ewertman at gmail.com
Tue Apr 29 01:38:51 EDT 2008
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 <kkuhl05 at gmail.com> 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
>
More information about the Python-list
mailing list