Fix example in atexit doc: Both open and read could raise the IOError (#10461 follow-up).
Thanks to SilenGhost for catching this.
diff --git a/Doc/library/atexit.rst b/Doc/library/atexit.rst
index fc2b5a7..db99eec 100644
--- a/Doc/library/atexit.rst
+++ b/Doc/library/atexit.rst
@@ -61,14 +61,11 @@
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