在Python程序中操作文件之flush()方法的使用教程,pythonflush
在Python程序中操作文件之flush()方法的使用教程,pythonflush
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
相关内容
- 讲解Python中fileno()方法的使用,pythonfileno
- 在Python程序中操作文件之isatty()方法的使用教程,pyth
- 在Python中使用next()方法操作文件的教程,pythonnext
- 在Python中操作文件之read()方法的使用教程,python使用教
- 简单介绍Python中的readline()方法的使用,pythonreadline
- 在Python中操作文件之seek()方法的使用教程,pythonseek
- Python中tell()方法的使用详解,python使用详解
- python实现统计代码行数的方法,python统计代码行数
- python从网络读取图片并直接进行处理的方法,
- Python3实现将文件归档到zip文件及从zip文件中读取数据的
评论关闭