cara membaca lalu menimpa file dengan python dengan truncate

 pythonCopywith open('myFolder/myfile.txt','r+') as myfile:
    data = myfile.read()
    myfile.seek(0)
    myfile.write('newData')
    myfile.truncate()
Shy Seal