Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e4f6a80

Browse files
committed
Fix example in atexit doc: Both open and read could raise the IOError (#10461 follow-up).
Thanks to SilenGhost for catching this.
1 parent e8eabe7 commit e4f6a80

1 file changed

Lines changed: 2 additions & 5 deletions

File tree

Doc/library/atexit.rst

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,11 @@ from a file when it is imported and save the counter's updated value
6161
automatically when the program terminates without relying on the application
6262
making an explicit call into this module at termination. ::
6363

64-
infile = open("/tmp/counter")
6564
try:
66-
_count = int(infile.read())
65+
with open("/tmp/counter") as infile:
66+
_count = int(infile.read())
6767
except IOError:
6868
_count = 0
69-
finally:
70-
infile.close()
71-
7269

7370
def incrcounter(n):
7471
global _count

0 commit comments

Comments
 (0)