def close ( self ) : if not self . closed : self . closed = True self . _flush ( finish = True ) self . _buffer = None
python should you flush before closing a file
Flush the buffer and finalize the file .
def close(self):
    """Flush the buffer and finalize the file.

    When this returns the new file is available for reading.
    """
    if not self.closed:
      self.closed = True
      self._flush(finish=True)
      self._buffer = None