mirror of
https://github.com/python/cpython.git
synced 2025-08-10 03:49:18 +00:00
#8522: use with statement instead of try-finally for file handling.
This commit is contained in:
parent
404bd7f473
commit
0b093e068e
1 changed files with 1 additions and 4 deletions
|
@ -232,11 +232,8 @@ file would not be closed when an exception is raised until the handler finishes,
|
|||
and perhaps not at all in non-C implementations (e.g., Jython). ::
|
||||
|
||||
def get_status(file):
|
||||
fp = open(file)
|
||||
try:
|
||||
with open(file) as fp:
|
||||
return fp.readline()
|
||||
finally:
|
||||
fp.close()
|
||||
|
||||
|
||||
Using the Batteries
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue