commit | 6cb7b6593ee03aedebae1bc9bd0f76912efa275a | [log] [tgz] |
---|---|---|
author | Georg Brandl <georg@python.org> | Sat Jul 31 20:08:15 2010 +0000 |
committer | Georg Brandl <georg@python.org> | Sat Jul 31 20:08:15 2010 +0000 |
tree | 30793f9f226d6e647e4bd3a9c6d14d3f24a9f775 | |
parent | e42a59daec40d1238a0189cde735f97aebe2d0b7 [diff] [blame] |
#1286: allow using fileinput.FileInput as context manager.
diff --git a/Lib/fileinput.py b/Lib/fileinput.py index 90a600b..a25a021 100644 --- a/Lib/fileinput.py +++ b/Lib/fileinput.py
@@ -238,6 +238,12 @@ self.nextfile() self._files = () + def __enter__(self): + return self + + def __exit__(self, type, value, traceback): + self.close() + def __iter__(self): return self