summaryrefslogtreecommitdiffstats
path: root/Doc/library
diff options
context:
space:
mode:
authorÉric Araujo <merwok@netwok.org>2011-03-12 14:56:09 (GMT)
committerÉric Araujo <merwok@netwok.org>2011-03-12 14:56:09 (GMT)
commite4f6a80ed843ac68ffbd1599d1dc0c55362df205 (patch)
treed1d585f263ba165f7391c0501fcefc0a27da4b94 /Doc/library
parente8eabe7b16bcee4000ceb5b801cf4dc807cb4b80 (diff)
downloadcpython-e4f6a80ed843ac68ffbd1599d1dc0c55362df205.zip
cpython-e4f6a80ed843ac68ffbd1599d1dc0c55362df205.tar.gz
cpython-e4f6a80ed843ac68ffbd1599d1dc0c55362df205.tar.bz2
Fix example in atexit doc: Both open and read could raise the IOError (#10461 follow-up).
Thanks to SilenGhost for catching this.
Diffstat (limited to 'Doc/library')
-rw-r--r--Doc/library/atexit.rst7
1 files changed, 2 insertions, 5 deletions
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 @@ 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