File Flush
# Python2.x Python File flush() Method
[ Python File Methods](#)
* * *
### Overview
The **flush()** method is used to flush the buffer, that is, to immediately write the data in the buffer to the file, while clearing the buffer, without passively waiting for the output buffer to be written.
Generally, the buffer is automatically flushed when the file is closed, but sometimes you need to flush it before closing, and you can use the flush() method at this time.
### Syntax
The syntax of the flush() method is as follows:
fileObject.flush();
### Parameters
* **None**
### Return Value
This method has no return value.
### Example
The following example demonstrates the use of the flush() method:
## Example
#!/usr/bin/python# -*- coding: UTF-8 -*-# Open file fo = open("tutorial.txt", "wb")print"File name: ", fo.name# Flush buffer fo.flush()# Close file fo.close()
The output of the above example is:
File name: tutorial.txt
[ Python File Methods](#)
YouTip