[Python-Dev] Possible py3k io wierdness
Greg Ewing
greg.ewing at canterbury.ac.nz
Mon Apr 6 00:39:43 CEST 2009
Brian Quinlan wrote:
> if not self.__closed:
> try:
> - self.flush()
> + IOBase.flush(self)
> except IOError:
> pass # If flush() fails, just give up
> self.__closed = True
That doesn't seem like a good idea to me at all. If
someone overrides flush() but not close(), their
flush method won't get called, which would be surprising.
To get the desired behaviour, you need something like
def close(self):
if not self.__closed:
self.flush()
self._close()
self.__closed = True
and then tell people to override _close() rather than
close().
--
Greg
More information about the Python-Dev
mailing list