English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
flush() The method is used to refresh the buffer, that is, the data in the buffer is immediately written to the file, and the buffer is cleared at the same time, without waiting passively for the output buffer to be written.
Generally, the buffer area is automatically refreshed after the file is closed, but sometimes you need to refresh it before closing it, and in this case, you can use the flush() method.
The syntax of the flush() method is as follows:
fileObject.flush();
None
This method does not return a value.
The following example demonstrates the use of the flush() method:
# Open the file fo = open("w",3codebox.txt", "wb") print("File name: ", fo.name) # Flush the buffer fo.flush() # Close the file fo.close()
The output result of the above example is as follows:
File name: w3codebox.txt