Merged revisions 81226 via svnmerge from

svn+ssh://pythondev@svn.python.org/python/branches/py3k

................
  r81226 | victor.stinner | 2010-05-16 02:36:38 +0200 (dim., 16 mai 2010) | 11 lines

  Merged revisions 81224 via svnmerge from
  svn+ssh://pythondev@svn.python.org/python/trunk

  ........
    r81224 | victor.stinner | 2010-05-16 02:34:40 +0200 (dim., 16 mai 2010) | 4 lines

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

    fo is not set if the open() fails.
  ........
................
This commit is contained in:
Victor Stinner 2010-05-16 00:37:36 +00:00
parent 0ac51bd1b6
commit f21d497b12
1 changed files with 4 additions and 6 deletions

View File

@ -66,13 +66,11 @@ class CommonTest(seq_tests.CommonTest):
d.append(d) d.append(d)
d.append(400) d.append(400)
try: try:
fo = open(support.TESTFN, "w") with open(support.TESTFN, "w") as fo:
fo.write(str(d)) fo.write(str(d))
fo.close() with open(support.TESTFN, "r") as fo:
fo = open(support.TESTFN, "r")
self.assertEqual(fo.read(), repr(d)) self.assertEqual(fo.read(), repr(d))
finally: finally:
fo.close()
os.remove(support.TESTFN) os.remove(support.TESTFN)
def test_set_subscript(self): def test_set_subscript(self):