[Python-checkins] r73408 - python/branches/py3k/Lib/test/test_import.py

benjamin.peterson python-checkins at python.org
Sat Jun 13 15:01:19 CEST 2009


Author: benjamin.peterson
Date: Sat Jun 13 15:01:19 2009
New Revision: 73408

Log:
make file closing more robust

Modified:
   python/branches/py3k/Lib/test/test_import.py

Modified: python/branches/py3k/Lib/test/test_import.py
==============================================================================
--- python/branches/py3k/Lib/test/test_import.py	(original)
+++ python/branches/py3k/Lib/test/test_import.py	Sat Jun 13 15:01:19 2009
@@ -46,13 +46,12 @@
             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]


More information about the Python-checkins mailing list