2 years ago

#62557

test-img

user17825405

how to close a file when open with os.close()

I have a piece of code which would save a file and after once clicked the tkinter button for saving it, python saves it every 5 minutes. But you could also open the saved file: so I need a piece of code which first tries to close the file (if open) and then save it again. This is my code:

def save_changes():
    # first close the saved_file
    wb.save(saved_file)
    cur_time = datetime.datetime.now().strftime("%H.%M.%S")
    saved_label.config(text="laatst opgeslagen op:\n" + cur_time)
    saved_label.after(300000, save_changes)

python

python-os

0 Answers

Your Answer

Accepted video resources