diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2016-12-14 12:16:34 -0800 |
---|---|---|
committer | Dylan Baker <dylan@pnwbakers.com> | 2016-12-14 15:43:39 -0800 |
commit | 15a724dfff40ec3b35af2526584e81ff82b4c40b (patch) | |
tree | c3adbbeae8951411622affa011c856acb3122c1f /alot/db/message.py | |
parent | fdb2d7103877185b6865e872cb06e7bdd237f9dc (diff) |
use open() as context manager
This uses open() as a context manager instead of calling close()
explicitly. This has the advantage of closing even in the event of an
exception, being easier to visually inspect for correctness, and being
the more modern idiom.
This does leave one case of file.close(), where FILE is opened in an if
tree.
Diffstat (limited to 'alot/db/message.py')
-rw-r--r-- | alot/db/message.py | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/alot/db/message.py b/alot/db/message.py index 91a0f420..0a129992 100644 --- a/alot/db/message.py +++ b/alot/db/message.py @@ -70,9 +70,8 @@ class Message(object): "Message file is no longer accessible:\n%s" % path if not self._email: try: - f_mail = open(path) - self._email = message_from_file(f_mail) - f_mail.close() + with open(path) as f: + self._email = message_from_file(f) except IOError: self._email = email.message_from_string(warning) return self._email |