how to read then overwrite a file with python with truncate

Solutions on MaxInterview for how to read then overwrite a file with python with truncate by the best coders in the world

showing results for - "how to read then overwrite a file with python with truncate"
Juan Manuel
11 Mar 2016
1 pythonCopywith open('myFolder/myfile.txt','r+') as myfile:
2    data = myfile.read()
3    myfile.seek(0)
4    myfile.write('newData')
5    myfile.truncate()
6
similar questions