Latest web development tutorials

Python3 File flush () method

Python3 File (File) method Python3 File (File) method


Outline

flush () method is used to flush the buffer, the data will be immediately written to the file in the buffer, clear the buffer at the same time, need not wait passively output buffer written.

Under normal circumstances, after the file is closed automatically refresh buffer, but sometimes you need to refresh before closing it, then you can use the flush () method.

grammar

flush () method has the following syntax:

fileObject.flush();

parameter

  • no

return value

This method has no return value.

Examples

The following example demonstrates the flush () method of use:

#!/usr/bin/python3

# 打开文件
fo = open("w3big.txt", "wb")
print ("文件名为: ", fo.name)

# 刷新缓冲区
fo.flush()

# 关闭文件
fo.close()

The above example output is:

文件名为:  w3big.txt

Python3 File (File) method Python3 File (File) method