mirror of
https://github.com/python/cpython.git
synced 2025-11-09 14:06:30 +00:00
Clean-up example of using fileinput as a context manager.
This commit is contained in:
parent
d5825ccd40
commit
7fefaffcc2
1 changed files with 3 additions and 2 deletions
|
|
@ -58,8 +58,9 @@ The following function is the primary interface of this module:
|
||||||
:keyword:`with` statement. In this example, *input* is closed after the
|
:keyword:`with` statement. In this example, *input* is closed after the
|
||||||
:keyword:`with` statement is exited, even if an exception occurs::
|
:keyword:`with` statement is exited, even if an exception occurs::
|
||||||
|
|
||||||
with fileinput.input(files=('spam.txt', 'eggs.txt')) as input:
|
with fileinput.input(files=('spam.txt', 'eggs.txt')) as f:
|
||||||
process(input)
|
for line in f:
|
||||||
|
process(line)
|
||||||
|
|
||||||
.. versionchanged:: 3.2
|
.. versionchanged:: 3.2
|
||||||
Can be used as a context manager.
|
Can be used as a context manager.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue