flushとはファイルを無理やり開くという意味ですか?
教材には確実にバッファからファイルの書き込みを実行させるためとありますが、よく意味がわかりません。
flush は何のためにあるのでしょうか?
また、他に flush を使った簡単な例などはありますか?
python
1#受け取ったfilepassの桁数を返す関数を書く。 2import unittest 3import tempfile 4 5def count(filepass): 6 with open(filepass, encoding='utf-8') as f: 7 lines = len(f.readlines()) 8 return lines 9 10class TestCount(unittest.TestCase): 11 def test_count(self): 12 13 with tempfile.NamedTemporaryFile(mode='w') as f1: 14 f1.write("""one 15two 16three""") 17 18 f1.flush() 19 actual = count(f1.name) 20 self.assertEqual(3, actual)

回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。