Forcing deletion of file. Python, Windows
I am working on a Reset button. The button is supposed to clear the text that is generated in a Text Widget and delete the file that the data was being written to. Clearing the Text Widget works, but I am having problems deleting the file.
When I try to delete it from windows, it says that it is still open in Python. So, I closed it from my code first, and then tried to delete it but didn't work.
I have programmed the other button so that it doesn't override files. So, I can't just delete the data that is already written in the file.
Is there any way that I can force the deletion of that file??
I am using Python 2.6.6.
This is my code on the reset button:
def reset_it(self):
self.run.upda开发者_运维问答te() # run is the other button, I have to stop it's processing!
self.Outputlines.update() # Forcing the TextWidget to update.
self.Outputlines.config(state=NORMAL)
self.Outputlines.delete(1.0, END) # Clearing everything from the TextWidget.
self.Outputlines.config(state=DISABLED)
self.run.wait_variable() # Stopping the run button.
self.infile.close() # Closing the file.
os.remove(self.filename.get()) # Code to delete the file.
精彩评论