about close a file in Python

后端 未结 5 1831
小鲜肉
小鲜肉 2021-02-08 18:57

I know it is a good habit of using close to close a file if not used any more in Python. I have tried to open a large number of open files, and not close them (in the same Pytho

5条回答
  •  一个人的身影
    2021-02-08 19:08

    You do need to close (output) files in Python.

    One example of why is to flush the output to them. If you don't properly close files and your program is killed for some reason, the left-open file can be corrupted.

    In addition, there is this: Why python has limit for count of file handles?

提交回复
热议问题