From 2258b39d647e0df0c524eb5224d9097702855848 Mon Sep 17 00:00:00 2001 From: "benjamin.peterson" Date: Sat, 13 Jun 2009 13:01:19 +0000 Subject: [PATCH] make file closing more robust git-svn-id: http://svn.python.org/projects/python/branches/py3k@73408 6015fed2-1504-0410-9fe1-9d1591cc4771 --- Lib/test/test_import.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Lib/test/test_import.py b/Lib/test/test_import.py index d30f905dd9..dbfadfb708 100644 --- a/Lib/test/test_import.py +++ b/Lib/test/test_import.py @@ -46,13 +46,12 @@ class ImportTest(unittest.TestCase): else: pyc = TESTFN + ".pyc" - f = open(source, "w") - print("# This tests Python's ability to import a", ext, "file.", file=f) - a = random.randrange(1000) - b = random.randrange(1000) - print("a =", a, file=f) - print("b =", b, file=f) - f.close() + with open(source, "w") as f: + print("# This tests Python's ability to import a", ext, "file.", file=f) + a = random.randrange(1000) + b = random.randrange(1000) + print("a =", a, file=f) + print("b =", b, file=f) if TESTFN in sys.modules: del sys.modules[TESTFN] -- 2.11.4.GIT