Python3-file-flush

提供:Dev Guides
移動先:案内検索

Python 3-ファイルflush()メソッド

説明

メソッド* flush()*は、stdioの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