English

Why it is important to close a file before exiting? - Computer Science (Python)

Advertisements
Advertisements

Question

Why it is important to close a file before exiting?

Short Answer

Solution

Files are limited resources handled by the operating system; closing files after use protects against difficult-to-debug issues such as running out of file handles or encountering corrupted data. Python does not flush the buffer that is writing data to the file until it is certain you are finished writing, which can be accomplished by closing the file. If you write to a file without closing it, the data will not be saved to the destination file.

shaalaa.com
Opening and Closing a CSV File in Python
  Is there an error in this question or solution?
2022-2023 (March) Set 4
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×