Title: Signature.html
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?

def modify_txt_file(old_fname, new_event_date):
    # Open old txt file and change first line with date & time of event
    # renaming will occur a little later
    #    old_fname is complete file name
    #    new_event_date is date like: Tue 2008/03/... 14: ...
    old_prefix = old_fname[0:19]
    input_file=open(old_fname,'r')
    #copy to temporary
    output_file=open(old_prefix+'.tmp','w')
    for j, line in enumerate(input_file):
        if j == 0: # replace header
            output_file.write("Event time: "+new_event_date)
            continue
        output_file.write(line) # copy other lines
    output_file.close()
    input_file.close()
    print "modified txt file with event info"
    # now copy tmp back to ...
    return
--
           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  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to