Read and overwrite a file in Python,f.close()