Como ler, em seguida, substitua um arquivo com python com truncado

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