diff options
author | Georg Brandl <georg@python.org> | 2010-04-25 10:18:59 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2010-04-25 10:18:59 (GMT) |
commit | a33971a3959f6c1a655f03830dc4b84e9cdc6d7f (patch) | |
tree | 3a8aea8adacd5f391eac819d0566911d5d09b2fe | |
parent | c689d96044be67ea6ad1195527e22390f17104b1 (diff) | |
download | cpython-a33971a3959f6c1a655f03830dc4b84e9cdc6d7f.zip cpython-a33971a3959f6c1a655f03830dc4b84e9cdc6d7f.tar.gz cpython-a33971a3959f6c1a655f03830dc4b84e9cdc6d7f.tar.bz2 |
Merged revisions 80461 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r80461 | georg.brandl | 2010-04-25 12:17:27 +0200 (So, 25 Apr 2010) | 1 line
#8522: use with statement instead of try-finally for file handling.
........
-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 f0c688b..05d8df9 100644 --- a/Doc/howto/doanddont.rst +++ b/Doc/howto/doanddont.rst @@ -232,11 +232,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 |