Skip to content

Commit

Permalink
make file closing more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminp committed Jun 13, 2009
1 parent 94f5583 commit 16a1f63
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions Lib/test/test_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,12 @@ def test_with_extension(ext):
else:
pyc = TESTFN + ".pyc"

f = open(source, "w")
print("# This tests Python's ability to import a", ext, "file.", file=f)
a = random.randrange(1000)
b = random.randrange(1000)
print("a =", a, file=f)
print("b =", b, file=f)
f.close()
with open(source, "w") as f:
print("# This tests Python's ability to import a", ext, "file.", file=f)
a = random.randrange(1000)
b = random.randrange(1000)
print("a =", a, file=f)
print("b =", b, file=f)

if TESTFN in sys.modules:
del sys.modules[TESTFN]
Expand Down

0 comments on commit 16a1f63

Please sign in to comment.