From bee5cef7dbff40734c347da5b93797e8db9103e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Araujo?= Date: Fri, 5 Nov 2010 23:51:56 +0000 Subject: Always close files in distutils code and tests (#10252). --- Lib/distutils/file_util.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'Lib/distutils/file_util.py') diff --git a/Lib/distutils/file_util.py b/Lib/distutils/file_util.py index 65aa7e0fdd..c36e7128d0 100644 --- a/Lib/distutils/file_util.py +++ b/Lib/distutils/file_util.py @@ -234,6 +234,8 @@ def write_file (filename, contents): sequence of strings without line terminators) to it. """ f = open(filename, "w") - for line in contents: - f.write(line + "\n") - f.close() + try: + for line in contents: + f.write(line + "\n") + finally: + f.close() -- cgit v1.2.1