Title: Signature.html
I'm using 2.4 for Win. I'll look into the tempfile module.
Tim Golden wrote:
Wayne
Watson wrote:
Enclosed is a segment of a program which
copies a txt file, but replaces the first line with a new one. The new
one has a suffix of tmp. After it executed the code and exited the
program normally (running out of code), I couldn't access the new tmp
file. It was listed by Win XP, but I got a "file in use" messge. Do I
have to exit differently to free the tmp file for inspection?
If you're using 2.5+, worth using the new with statement which
should ensure file closure, altho' there's nothing in your
code which suggests that it shouldn't close anyhow. Also,
for the purpose of your copy-except-line-1 routine, consider
that files are also iterators. Put together, this snippet --
simplified for clarity -- might help things along:
<code>
from __future__ import with_statement
with open ("c:/temp/temp0.txt") as fin:
with open ("c:/temp/temp1.txt", "w") as fout:
fout.write ("NEW LINE 1\n")
fin.next ()
fout.writelines (fin)
</code>
Just in case it helps, it is possible for virus checkers
and the like (and viruses themselves for that matter) to
monitor file creation and to lock the file in share-delete
mode. If what you have is a truly temporary file, consider
using the tempfile module or at least creating it in the
%TEMP% directory which will generally be excluded for
virus checking, I think.
TJG
_______________________________________________
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
--
Wayne Watson (Watson Adventures, Prop., Nevada City, CA)
(121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
Obz Site: 39° 15' 7" N, 121° 2' 32" W, 2700 feet
"If voting made any difference they wouldn't let us do it."
-- Mark Twain
Web Page: <www.speckledwithstars.net/>
|
_______________________________________________
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor