diff options
Diffstat (limited to 'Doc/howto/doanddont.rst')
-rw-r--r-- | Doc/howto/doanddont.rst | 5 |
1 files changed, 1 insertions, 4 deletions
diff --git a/Doc/howto/doanddont.rst b/Doc/howto/doanddont.rst index a9302ed..071eb2a 100644 --- a/Doc/howto/doanddont.rst +++ b/Doc/howto/doanddont.rst @@ -199,11 +199,8 @@ 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). :: def get_status(file): - fp = open(file) - try: + with open(file) as fp: return fp.readline() - finally: - fp.close() Using the Batteries |