From: Éric Araujo Date: Sat, 12 Mar 2011 14:56:09 +0000 (+0100) Subject: Fix example in atexit doc: Both open and read could raise the IOError (#10461 follow... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e4f6a80ed843ac68ffbd1599d1dc0c55362df205;p=python 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 fc2b5a78b7..db99eecbbb 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