发布于 2015-06-21 10:44:23 | 610 次阅读 | 评论: 0 | 来源: 网络整理

flush()方法刷新内部缓冲区,像标准输入输出的fflush。这类似文件的对象,无操作。

Python关闭时自动刷新文件。但是可能要关闭任何文件之前刷新数据。

语法

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


fileObject.flush(); 

参数

  • NA

返回值

此方法不返回任何值。

例子

下面的例子显示了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
最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务