Does Python automatically flush its buffer when calling seek and/or read operations following a write?

前端 未结 1 1476
情歌与酒
情歌与酒 2021-02-14 09:28

Let\'s say I write the following python code:

file = open(\"test.txt\",\"w+\")
file.write(\"hi\")
file.seek(0)
file.read()

The second line tell

相关标签:
1条回答
  • 2021-02-14 10:26

    For specifically CPython, for buffered IO seek calls the _io__Buffered_seek_impl which is guaranteed to flush if and only if the whence argument is set to SEEK_END (2)

    read with zero arguments calls _bufferedreader_read_all through _io__Buffered_read_impl, which does flush.

    0 讨论(0)
提交回复
热议问题