diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2015-04-04 08:01:02 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-04-04 08:01:02 (GMT) |
commit | 46ba6c8563922f043cad6423202ee0119614c807 (patch) | |
tree | 4523d1a3665af25ef77898f7d2da186fbdca8ce7 /Lib/dbm | |
parent | ae2d667ae83548029fed7244619fadd7f625cb24 (diff) | |
download | cpython-46ba6c8563922f043cad6423202ee0119614c807.zip cpython-46ba6c8563922f043cad6423202ee0119614c807.tar.gz cpython-46ba6c8563922f043cad6423202ee0119614c807.tar.bz2 |
Issue #22831: Use "with" to avoid possible fd leaks.
Diffstat (limited to 'Lib/dbm')
-rw-r--r-- | Lib/dbm/__init__.py | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/Lib/dbm/__init__.py b/Lib/dbm/__init__.py index 5f4664a..6831a84 100644 --- a/Lib/dbm/__init__.py +++ b/Lib/dbm/__init__.py @@ -153,9 +153,9 @@ def whichdb(filename): except OSError: return None - # Read the start of the file -- the magic number - s16 = f.read(16) - f.close() + with f: + # Read the start of the file -- the magic number + s16 = f.read(16) s = s16[0:4] # Return "" if not at least 4 bytes |