Python3 file.flush()方法

flush()方法刷新內部緩衝,就像標準輸入fflush。這可能是一些類檔對象的空操作。

Python關閉它們時自動刷新檔。 但你可能要關閉檔之前刷新數據。

語法

以下是 flush()方法的語法 -
fileObject.flush()

參數

  • NA

返回值

此方法不返回任何值。

示例

下麵的示例說明 flush()方法的使用。
#!/usr/bin/python3

# 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

上一篇: Python3模組 下一篇: Python3檔方法