Buffering Data

We keep telling you that you always need to close your files after you're done writing to them. Here's why!

During the I/O process, data is buffered: this means that it is held in a temporary location before being written to the file.

Python doesn't flush the buffer—that is, write data to the file—until it's sure you're done writing. One way to do this is to close the file. If you write to a file without closing, the data won't make it to the target file.

posted @ 2017-06-12 15:47  2021年的顺遂平安君  阅读(48)  评论(0编辑  收藏  举报