[Python-checkins] cpython: Fix example in atexit doc: Both open and read could raise the IOError (#10461
eric.araujo
python-checkins at python.org
Sat Mar 12 15:56:29 CET 2011
http://hg.python.org/cpython/rev/cebaf1bdaf78
changeset: 68398:cebaf1bdaf78
user: Éric Araujo <merwok at netwok.org>
date: Sat Mar 12 15:56:09 2011 +0100
summary:
Fix example in atexit doc: Both open and read could raise the IOError (#10461 follow-up).
Thanks to SilenGhost for catching this.
files:
Doc/library/atexit.rst
diff --git a/Doc/library/atexit.rst b/Doc/library/atexit.rst
--- 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
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list