From 165cf5cb4f044142a608397c71c6ec5caca154c7 Mon Sep 17 00:00:00 2001 From: Sebastian Spaeth Date: Thu, 19 Jan 2012 11:55:06 +0100 Subject: [PATCH] Use modern "with open() as file" Saves a LOC and guarantees that the file will be closed Signed-off-by: Sebastian Spaeth --- offlineimap/folder/Base.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/offlineimap/folder/Base.py b/offlineimap/folder/Base.py index 30dfac2..5e3d1e5 100644 --- a/offlineimap/folder/Base.py +++ b/offlineimap/folder/Base.py @@ -154,9 +154,8 @@ class BaseFolder(object): newval = self.get_uidvalidity() uidfilename = self._getuidfilename() - file = open(uidfilename + ".tmp", "wt") - file.write("%d\n" % newval) - file.close() + with open(uidfilename + ".tmp", "wt") as file: + file.write("%d\n" % newval) os.rename(uidfilename + ".tmp", uidfilename) self._base_saved_uidvalidity = newval