mirror of
https://github.com/python/cpython.git
synced 2026-01-06 07:22:09 +00:00
Fix example in atexit doc: Both open and read could raise the IOError (#10461 follow-up).
Thanks to SilenGhost for catching this.
This commit is contained in:
parent
e8eabe7b16
commit
e4f6a80ed8
1 changed files with 2 additions and 5 deletions
|
|
@ -61,14 +61,11 @@ from a file when it is imported and save the counter's updated value
|
|||
automatically when the program terminates without relying on the application
|
||||
making an explicit call into this module at termination. ::
|
||||
|
||||
infile = open("/tmp/counter")
|
||||
try:
|
||||
_count = int(infile.read())
|
||||
with open("/tmp/counter") as infile:
|
||||
_count = int(infile.read())
|
||||
except IOError:
|
||||
_count = 0
|
||||
finally:
|
||||
infile.close()
|
||||
|
||||
|
||||
def incrcounter(n):
|
||||
global _count
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue