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 ...@@ -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 automatically when the program terminates without relying on the application
making an explicit call into this module at termination. :: making an explicit call into this module at termination. ::
infile = open("/tmp/counter")
try: try:
with open("/tmp/counter") as infile:
_count = int(infile.read()) _count = int(infile.read())
except IOError: except IOError:
_count = 0 _count = 0
finally:
infile.close()
def incrcounter(n): def incrcounter(n):
global _count 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