Python File flush() 方法

Python 教程 · 2019-02-03 13:59:05

概述

flush() 方法是用来刷新缓冲区的,即将缓冲区中的数据立刻写入文件,同时清空缓冲区,不需要是被动的等待输出缓冲区写入。

一般情况下,文件关闭后会自动刷新缓冲区,但有时你需要在关闭前刷新它,这时就可以使用 flush() 方法。

语法

flush() 方法语法如下:

fileObject.flush();

参数

返回值

该方法没有返回值。

实例

以下实例演示了 flush() 方法的使用:

实例

#!/usr/bin/python # -*- coding: UTF-8 -*- # 打开文件 fo = open("codercto.txt", "wb") print "文件名为: ", fo.name # 刷新缓冲区 fo.flush() # 关闭文件 fo.close()

以上实例输出结果为:

文件名为:  codercto.txt

点击查看所有 Python 教程 文章: https://www.codercto.com/courses/l/8.html

查看所有标签

Programming Amazon Web Services

Programming Amazon Web Services

James Murty / O'Reilly Media / 2008-3-25 / USD 49.99

Building on the success of its storefront and fulfillment services, Amazon now allows businesses to "rent" computing power, data storage and bandwidth on its vast network platform. This book demonstra......一起来看看 《Programming Amazon Web Services》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具