'Flush and close the IO object.
This method has no effect if the file is already closed.'

def close(self):

    if (not self.__closed):
        try:
            self.flush()
        finally:
            self.__closed = True
