summaryrefslogtreecommitdiff
path: root/Lib/fileinput.py
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2010-07-31 20:08:15 +0000
committerGeorg Brandl <georg@python.org>2010-07-31 20:08:15 +0000
commit6cb7b6593ee03aedebae1bc9bd0f76912efa275a (patch)
tree30793f9f226d6e647e4bd3a9c6d14d3f24a9f775 /Lib/fileinput.py
parente42a59daec40d1238a0189cde735f97aebe2d0b7 (diff)
downloadcpython-git-6cb7b6593ee03aedebae1bc9bd0f76912efa275a.tar.gz
#1286: allow using fileinput.FileInput as context manager.
Diffstat (limited to 'Lib/fileinput.py')
-rw-r--r--Lib/fileinput.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/Lib/fileinput.py b/Lib/fileinput.py
index 90a600bf11..a25a021eb3 100644
--- a/Lib/fileinput.py
+++ b/Lib/fileinput.py
@@ -238,6 +238,12 @@ class FileInput:
self.nextfile()
self._files = ()
+ def __enter__(self):
+ return self
+
+ def __exit__(self, type, value, traceback):
+ self.close()
+
def __iter__(self):
return self