Python file method flush() flushes the internal buffer, like stdio's fflush. This may be a no-op on some file-like objects.
Python automatically flushes the files when closing them. But you may want to flush the data before closing any file.
Following is the syntax for the flush() method:
This method does not return any value.
The following example shows the usage of the flush() method.
#!/usr/bin/python # Open a file fo = open("foo.txt", "wb") print "Name of the file: ", fo.name # Here it does nothing, but you can call it with read operation. fo.flush() # Close opend file fo.close()
When we run the above program, it produces the following result:
Name of the file: foo.txt
Here at Intellinuts, we have created a complete Python tutorial for Beginners to get started in Python.