Commit 8a470d60 authored by Victor Stinner's avatar Victor Stinner

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

fo is not set if the open() fails.
parent 3bea1ede
...@@ -57,13 +57,11 @@ class CommonTest(seq_tests.CommonTest): ...@@ -57,13 +57,11 @@ class CommonTest(seq_tests.CommonTest):
d.append(d) d.append(d)
d.append(400) d.append(400)
try: try:
fo = open(test_support.TESTFN, "wb") with open(test_support.TESTFN, "wb") as fo:
print >> fo, d, print >> fo, d,
fo.close() with open(test_support.TESTFN, "rb") as fo:
fo = open(test_support.TESTFN, "rb") self.assertEqual(fo.read(), repr(d))
self.assertEqual(fo.read(), repr(d))
finally: finally:
fo.close()
os.remove(test_support.TESTFN) os.remove(test_support.TESTFN)
def test_set_subscript(self): def test_set_subscript(self):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment