I am in Terminal on mac and I am learning how to open, close, read, delete files.
When I set
f = open("sample.txt", 'w')
f.write() writes into the Python process's own buffer (similarly to the C
fwrite() functions). However, the data is not actually flushed into the OS buffers until you call
f.close(), or when the buffer fills up. Once you do that, the data becomes visible to all other applications.
Note that the OS does another layer of buffering/caching -- that is shared by all running applications. When the file is flushed, it's written to these buffers, but is not yet written to the disk until some time has passed, or when you call
fsync(). If your OS crashes or computer loses power, such unsaved changes will be lost.