From 723f1a4fc12f7af4b7a2c404a484d6fe6ae01510 Mon Sep 17 00:00:00 2001 From: Wirawan Purwanto Date: Sat, 2 Aug 2014 21:32:34 -0400 Subject: [PATCH] * Added __enter__/__exit__ method for use with python 2.5's "with" statement. --- iofmt/text_output.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/iofmt/text_output.py b/iofmt/text_output.py index 9cd4c3a..d20149c 100644 --- a/iofmt/text_output.py +++ b/iofmt/text_output.py @@ -110,6 +110,10 @@ class text_output(object): def __del__(self): #print "Deleting object %s, file %s" % (self, self.out) self.close() + def __enter__(self): + return self + def __exit__(self, type, value, traceback): + self.close() def set_write_func(self, method): """Sets the default '_output' function to a python bound method. Always use this method, instead of setting self._output directly!