Python3 File flush() 方法
Python 3 教程
· 2019-02-06 22:13:37
概述
flush() 方法是用来刷新缓冲区的,即将缓冲区中的数据立刻写入文件,同时清空缓冲区,不需要是被动的等待输出缓冲区写入。
一般情况下,文件关闭后会自动刷新缓冲区,但有时你需要在关闭前刷新它,这时就可以使用 flush() 方法。
语法
flush() 方法语法如下:
fileObject.flush();
参数
无
返回值
该方法没有返回值。
实例
以下实例演示了 flush() 方法的使用:
#!/usr/bin/python3
# 打开文件
fo = open("codercto.txt", "wb")
print ("文件名为: ", fo.name)
# 刷新缓冲区
fo.flush()
# 关闭文件
fo.close()
以上实例输出结果为:
文件名为: codercto.txt
点击查看所有 Python 3 教程 文章: https://codercto.com/courses/l/10.html
BSD Hacks
Dru Lavigne / O'Reilly Media, Inc. / 2004-05-24 / USD 24.95
If you want more than your average BSD user--you want to explore and experiment, unearth shortcuts, create useful tools, and come up with fun things to try on your own--BSD Hacks is a must-have. This ......一起来看看 《BSD Hacks》 这本书的介绍吧!