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

前端 未结 7 2117
旧时难觅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条回答
  •  情歌与酒
    2020-11-29 03:53

    You need to f.close() to flush the file write buffer out to the file. Or in your case you might just want to do a f.flush(); os.fsync(); so you can keep looping with the opened file handle.

    Don't forget to import os.

提交回复
热议问题