[Python-checkins] r81224 - python/trunk/Lib/test/list_tests.py

victor.stinner python-checkins at python.org
Sun May 16 02:34:40 CEST 2010


Author: victor.stinner
Date: Sun May 16 02:34:40 2010
New Revision: 81224

Log:
Use with open() as fo: ... instead of try: fo = open(...) finally: fo.close()

fo is not set if the open() fails.


Modified:
   python/trunk/Lib/test/list_tests.py

Modified: python/trunk/Lib/test/list_tests.py
==============================================================================
--- python/trunk/Lib/test/list_tests.py	(original)
+++ python/trunk/Lib/test/list_tests.py	Sun May 16 02:34:40 2010
@@ -57,13 +57,11 @@
         d.append(d)
         d.append(400)
         try:
-            fo = open(test_support.TESTFN, "wb")
-            print >> fo, d,
-            fo.close()
-            fo = open(test_support.TESTFN, "rb")
-            self.assertEqual(fo.read(), repr(d))
+            with open(test_support.TESTFN, "wb") as fo:
+                print >> fo, d,
+            with open(test_support.TESTFN, "rb") as fo:
+                self.assertEqual(fo.read(), repr(d))
         finally:
-            fo.close()
             os.remove(test_support.TESTFN)
 
     def test_set_subscript(self):


More information about the Python-checkins mailing list