Use modern "with open() as file"

Saves a LOC and guarantees that the file will be closed

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
This commit is contained in:
Sebastian Spaeth 2012-01-19 11:55:06 +01:00
parent de1e03b065
commit 165cf5cb4f

View File

@ -154,9 +154,8 @@ class BaseFolder(object):
newval = self.get_uidvalidity() newval = self.get_uidvalidity()
uidfilename = self._getuidfilename() uidfilename = self._getuidfilename()
file = open(uidfilename + ".tmp", "wt") with open(uidfilename + ".tmp", "wt") as file:
file.write("%d\n" % newval) file.write("%d\n" % newval)
file.close()
os.rename(uidfilename + ".tmp", uidfilename) os.rename(uidfilename + ".tmp", uidfilename)
self._base_saved_uidvalidity = newval self._base_saved_uidvalidity = newval