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

查看所有标签

Web Data Mining

Web Data Mining

Bing Liu / Springer / 2011-6-26 / CAD 61.50

Web mining aims to discover useful information and knowledge from Web hyperlinks, page contents, and usage data. Although Web mining uses many conventional data mining techniques, it is not purely an ......一起来看看 《Web Data Mining》 这本书的介绍吧!

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

html转js在线工具
html转js在线工具

html转js在线工具