Account
Categories

flush() Method


The flush() method is used to immediately save data into a file by clearing the internal buffer.

It forces the data to be written into the file without waiting.

Syntax

file_object.flush()

Example

file = open("file1.txt", "w")

file.write("Hello Python")
file.flush()

file.close()

Output

Exercise

Create a file and use the flush() method to immediately save data into the file.