How come a file doesn't get written until I stop the program?

前端 未结 7 2131
旧时难觅i
旧时难觅i 2020-11-29 03:31

I\'m running a test, and found that the file doesn\'t actually get written until I control-C to abort the program. Can anyone explain why that would happen?

I expec

7条回答
  •  旧时难觅i
    2020-11-29 04:08

    This is a windows-ism. If you add an explicit .close() when you're done with file, it'll appear in explorer at that time. Even just flushing it might be enough (I don't have a windows box handy to test). But basically f.write does not actually write, it just appends to the write buffer - until the buffer gets flushed you won't see it.

    On unix the files will typically show up as a 0-byte file in this situation.

提交回复
热议问题