mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
#1286: allow using fileinput.FileInput as context manager.
This commit is contained in:
parent
e42a59daec
commit
6cb7b6593e
4 changed files with 59 additions and 7 deletions
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue