summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2009-06-13 13:01:19 (GMT)
committerBenjamin Peterson <benjamin@python.org>2009-06-13 13:01:19 (GMT)
commit16a1f6343f0c13b4a4366ba2cf5b344ff0e72b38 (patch)
treea737c94c697574880e23ad7445b6fc125f834cad /Lib
parent94f55837775f00eade742fa015d818633ab68318 (diff)
downloadcpython-16a1f6343f0c13b4a4366ba2cf5b344ff0e72b38.zip
cpython-16a1f6343f0c13b4a4366ba2cf5b344ff0e72b38.tar.gz
cpython-16a1f6343f0c13b4a4366ba2cf5b344ff0e72b38.tar.bz2
make file closing more robust
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_import.py13
1 files changed, 6 insertions, 7 deletions
diff --git a/Lib/test/test_import.py b/Lib/test/test_import.py
index d30f905..dbfadfb7 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]