Python3 file.flush()方法

flush()方法刷新内部缓冲,就像标准输入fflush。这可能是一些类文件对象的空操作。

Python关闭它们时自动刷新文件。 但你可能要关闭文件之前刷新数据。

语法

以下是 flush()方法的语法 -
fileObject.flush()

参数

  • NA

返回值

此方法不返回任何值。

示例

下面的示例说明 flush()方法的使用。
#!/usr/bin/python3

# 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()
当我们运行上面的程序,会产生以下结果 -
Name of the file:  foo.txt

上一篇: Python3模块 下一篇: Python3文件方法