Commit 0b093e06 authored by Georg Brandl's avatar Georg Brandl

#8522: use with statement instead of try-finally for file handling.

parent 404bd7f4
...@@ -232,11 +232,8 @@ file would not be closed when an exception is raised until the handler finishes, ...@@ -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). :: and perhaps not at all in non-C implementations (e.g., Jython). ::
def get_status(file): def get_status(file):
fp = open(file) with open(file) as fp:
try:
return fp.readline() return fp.readline()
finally:
fp.close()
Using the Batteries Using the Batteries
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment