Index: Doc/library/atexit.rst =================================================================== --- Doc/library/atexit.rst (revision 86561) +++ Doc/library/atexit.rst (working copy) @@ -67,7 +67,8 @@ making an explicit call into this module at termination. :: try: - _count = int(open("/tmp/counter").read()) + with open("/tmp/counter") as infile: + _count = int(infile.read()) except IOError: _count = 0 @@ -76,7 +77,8 @@ _count = _count + n def savecounter(): - open("/tmp/counter", "w").write("%d" % _count) + with open("/tmp/counter", "w") as outfile: + outfile.write("%d" % _count) import atexit atexit.register(savecounter)