diff options
author | Benjamin Peterson <benjamin@python.org> | 2009-06-13 13:01:19 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2009-06-13 13:01:19 (GMT) |
commit | 16a1f6343f0c13b4a4366ba2cf5b344ff0e72b38 (patch) | |
tree | a737c94c697574880e23ad7445b6fc125f834cad /Lib | |
parent | 94f55837775f00eade742fa015d818633ab68318 (diff) | |
download | cpython-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.py | 13 |
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] |