read and overwrite a file in python,f.close()