deleting file if it exists; python

You’re trying to delete an open file, and the docs for os.remove() state… On Windows, attempting to remove a file that is in use causes an exception to be raised You could change the code to… …or you can replace all that with… …which will truncate the file to zero length before opening.