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/commands | |
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/commands')
-rw-r--r-- | alot/commands/envelope.py | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/alot/commands/envelope.py b/alot/commands/envelope.py index 2c35c2aa..52ce5be9 100644 --- a/alot/commands/envelope.py +++ b/alot/commands/envelope.py @@ -324,10 +324,9 @@ class EditCommand(Command): # get input # tempfile will be removed on buffer cleanup - f = open(self.envelope.tmpfile.name) enc = settings.get('editor_writes_encoding') - template = string_decode(f.read(), enc) - f.close() + with open(self.envelope.tmpfile.name) as f: + template = string_decode(f.read(), enc) # call post-edit translate hook translate = settings.get_hook('post_edit_translate') |