This page is in draft mode. Only editors can see it listed. Any user with 100 rep with the link may edit it.
  • file
  • newbie

Modern operating systems use buffering when writing to files. When you explicitly close or flush a file handle, you ensure that all the pending output actually gets written out to the open file. Conversely, when you fail to do that, you may experience data loss.

The conventional solution in Python is to use with open(...) which handles the closing of the file handle implicitly even in exceptional circumstances.