Flushes the write buffers of the file.
It works like stdio‘s fflush(). This may be a no-op on some file-like objects. flush() does not necessarily write the file’s data to disk. Use flush() followed by os.fsync() to ensure this behavior.
>>> fw = open(r'C:\test.txt', "w") >>> fw.write('foobar') >>> fr = open(r'C:\test.txt') >>> fr.readlines() # even though we just wrote a line to the fr file it appears empty until close() method is called  >>> fw.flush() # flushing forces the buffer content into the file without closing it >>> fr.readlines() ['foobar']