File IO Issues, help :(

Tim Roberts timr at
Wed Apr 30 08:32:21 CEST 2008

Kevin K <kkuhl05 at> wrote:

>On Apr 29, 12:38 am, "Eric Wertman" <ewert... at> wrote:
>> 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.
>Yeah sorry I forgot to include the close() in the quote but its there.
>In fact I moved it up a bit and still no luck heres the new code:
>jsfile = open("../timeline.js", "r+")
>jscontent = jsfile.readlines()
>for line in jscontent:
>	if'var d =', line):
>		line = "var d = \""+mint['1'].ascdate()+"\"\n"
>		print line
>	jsfile.write(line)
>I tried this can got the same result...??

That's not what he meant.  He meant:

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

You have to decide whether this makes more sense to you than the
seek/truncate solution.  Personally, I'd prefer the close/open.

Or even:

jscontent = open("../timeline.js", "r").readlines()
jsfile = open("../timeline.js", "w")
... etc ...
Tim Roberts, timr at
Providenza & Boekelheide, Inc.

More information about the Python-list mailing list