Arquivo aberto RW Python

with open(filename, "r+") as f:
    data = f.read()
    f.seek(0)
    f.write(output)
    f.truncate()
BeRMOoDA