how to read then overwrite a file with python

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

showing results for - "how to read then overwrite a file with python"
Gabriele
01 Jan 2020
1 pythonCopywith open('myFolder/myfile.txt', "r") as myfile:
2    data = myfilef.read()
3
4with open('myFolder/myfile.txt', "w") as myfile:
5    myfile.write(newData)
6