]> granicus.if.org Git - python/commitdiff
Fix example in atexit doc: Both open and read could raise the IOError (#10461 follow...
authorÉric Araujo <merwok@netwok.org>
Sat, 12 Mar 2011 14:56:09 +0000 (15:56 +0100)
committerÉric Araujo <merwok@netwok.org>
Sat, 12 Mar 2011 14:56:09 +0000 (15:56 +0100)
Thanks to SilenGhost for catching this.

Doc/library/atexit.rst

index fc2b5a78b797654106ec2169ebf9710b2901932a..db99eecbbbc5beb8610bca395001faafb2a1216e 100644 (file)
@@ -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