summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2010-05-16 00:34:40 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2010-05-16 00:34:40 (GMT)
commit8a470d6039ffe85ea2e0f095fd0f0b960f099b94 (patch)
treefb45d78c7f4c9ae678bc3a1b43807ce373b323d9
parent3bea1ede7d260484f66b1ee4e3e20d65e3bf9bd1 (diff)
downloadcpython-8a470d6039ffe85ea2e0f095fd0f0b960f099b94.zip
cpython-8a470d6039ffe85ea2e0f095fd0f0b960f099b94.tar.gz
cpython-8a470d6039ffe85ea2e0f095fd0f0b960f099b94.tar.bz2
Use with open() as fo: ... instead of try: fo = open(...) finally: fo.close()
fo is not set if the open() fails.
-rw-r--r--Lib/test/list_tests.py10
1 files changed, 4 insertions, 6 deletions
diff --git a/Lib/test/list_tests.py b/Lib/test/list_tests.py
index e2fa9fe..546416e 100644
--- a/Lib/test/list_tests.py
+++ b/Lib/test/list_tests.py
@@ -57,13 +57,11 @@ class CommonTest(seq_tests.CommonTest):
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):