目录

file.flush()

描述 (Description)

方法flush()刷新内部缓冲区,就像stdio的fflush一样。 这可能是某些类文件对象的无操作。

关闭文件时,Python会自动刷新文件。 但您可能希望在关闭任何文件之前刷新数据。

语法 (Syntax)

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

fileObject.flush(); 

参数 (Parameters)

  • NA

返回值 (Return Value)

此方法不返回任何值。

例子 (Example)

以下示例显示了flush()方法的用法。

#!/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()

当我们运行上面的程序时,它产生以下结果 -

Name of the file:  foo.txt
↑回到顶部↑
WIKI教程 @2018