From 0b093e068e47f26e81674a6cf124a32377317cd7 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Sun, 25 Apr 2010 10:17:27 +0000 Subject: [PATCH] #8522: use with statement instead of try-finally for file handling. --- Doc/howto/doanddont.rst | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Doc/howto/doanddont.rst b/Doc/howto/doanddont.rst index f0c688bf2d1..05d8df9db93 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