mirror of
https://github.com/python/cpython.git
synced 2026-05-03 00:58:30 +00:00
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:
parent
3bea1ede7d
commit
8a470d6039
1 changed files with 4 additions and 6 deletions
|
|
@ -57,13 +57,11 @@ def test_print(self):
|
|||
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):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue