Index: Doc/howto/doanddont.rst =================================================================== --- Doc/howto/doanddont.rst (revision 84067) +++ Doc/howto/doanddont.rst (working copy) @@ -185,7 +185,7 @@ So, try to make as few ``except`` clauses in your code --- those will usually be a catch-all in the :func:`main`, or inside calls which should always succeed. -So, the best version is probably :: +So, an even better version is probably :: def get_status(file): return open(file).readline() @@ -196,7 +196,9 @@ The last version is not very good either --- due to implementation details, the file would not be closed when an exception is raised until the handler finishes, -and perhaps not at all in non-C implementations (e.g., Jython). :: +and perhaps not at all in non-C implementations (e.g., Jython). So it would be +even better to use the ``open()`` call as a context manager to ensure the file +gets closed as soon as the function returns:: def get_status(file): with open(file) as fp: