about close a file in Python

后端 未结 5 1800
小鲜肉
小鲜肉 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:11

    There are two good reasons.

    1. If your program crashes or is unexpectedly terminated, then output files may be corrupted.
    2. It's good practice to close what you open.

提交回复
热议问题