YouTip LogoYouTip

Python3 File Flush

# Python3.x Python3 File flush() Method [![Image 3: Python3 File Methods](#) Python3 File Methods](#) * * * ### Overview The **flush()** method is used to flush the buffer, which means writing the data in the buffer to the file immediately and clearing the buffer, without having to passively wait for the output buffer to be written. Generally, the buffer is automatically flushed after the file is closed, but sometimes you need to flush it before closing, and this is where the flush() method can be used. ### Syntax The syntax for the flush() method is as follows: fileObject.flush(); ### Parameters * **None** ### Return Value This method does not return a value. ### Example The following example demonstrates the use of the flush() method: #!/usr/bin/python3# Open the file fo = open(".txt", "wb")print ("File name: ", fo.name)# Flush the buffer fo.flush()# Close the file fo.close() The output of the above example is: File name: .txt * * Python3 File Methods](#)
← Java Arraylist RemoveifJava Arraylist Removerange β†’