Python file方法flush()刷新内部缓冲区,就像stdio的fflush一样。这可能是对某些类似文件的对象的无操作。
Python会在关闭文件时自动刷新这些文件。但您可能希望在关闭任何文件之前刷新数据。
链接:https://www.learnfk.comhttps://www.learnfk.com/python/file-flush.html
来源:LearnFk无涯教程网
fileObject.flush();
以下示例显示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
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)