Método Python File flush()
Exemplo
Você pode limpar o buffer ao gravar em um arquivo:
f = open("myfile.txt", "a")
f.write("Now the file has one more line!")
f.flush()
f.write("...and another one!")
Definição e uso
O flush()
método limpa o buffer interno.
Sintaxe
file.flush()
Valores de parâmetro
Sem parâmetros