does close() imply flush() in Python? does close() imply flush() in Python? python python

does close() imply flush() in Python?


Yes. It uses the underlying close() function which does that for you (source).


NB: close() and flush() won't ensure that the data is actually secure on the disk. It just ensures that the OS has the data == that it isn't buffered inside the process.

You can try sync or fsync to get the data written to the disk.


Yes, in Python 3 this is finally in the official documentation, but is was already the case in Python 2 (see Martin's answer).