Commit e4f6a80e authored by Éric Araujo's avatar Éric Araujo

Fix example in atexit doc: Both open and read could raise the IOError (#10461 follow-up).

Thanks to SilenGhost for catching this.
parent e8eabe7b
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment