flush()方法刷新內部緩沖區,像標準輸入輸出的fflush。這類似文件的對象,無操作。
Python關閉時自動刷新文件。但是可能要關閉任何文件之前刷新數據。
語法
以下是flush()方法的語法:
fileObject.flush();
參數
NA返回值
此方法不返回任何值。
例子
下面的例子顯示了flush()方法的使用。
#!/usr/bin/python# Open a filefo = 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 filefo.close()
當我們運行上面的程序,它會產生以下結果:
Name of the file: foo.txt
新聞熱點
疑難解答