summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2010-04-25 10:17:27 (GMT)
committerGeorg Brandl <georg@python.org>2010-04-25 10:17:27 (GMT)
commit0b093e068e47f26e81674a6cf124a32377317cd7 (patch)
tree57dd49557c41dc40f24c145cc8dc90f4d59525ec /Doc
parent404bd7f473314bcef9d92f1c695d0275f9d5d397 (diff)
downloadcpython-0b093e068e47f26e81674a6cf124a32377317cd7.zip
cpython-0b093e068e47f26e81674a6cf124a32377317cd7.tar.gz
cpython-0b093e068e47f26e81674a6cf124a32377317cd7.tar.bz2
#8522: use with statement instead of try-finally for file handling.
Diffstat (limited to 'Doc')
-rw-r--r--Doc/howto/doanddont.rst5
1 files changed, 1 insertions, 4 deletions
diff --git a/Doc/howto/doanddont.rst b/Doc/howto/doanddont.rst
index f0c688b..05d8df9 100644
--- a/Doc/howto/doanddont.rst
+++ b/Doc/howto/doanddont.rst
@@ -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