use with open

This commit is contained in:
Fabian Affolter 2015-06-20 23:03:53 +02:00
parent 832e9a631e
commit ef40b94a87

View File

@ -62,7 +62,7 @@ class FileNotificationService(BaseNotificationService):
def send_message(self, message="", **kwargs):
""" Send a message to a file. """
file = open(self.filepath, 'a')
with open(self.filepath, 'a') as file:
if os.stat(self.filepath).st_size == 0:
title = '{} notifications (Log started: {})\n{}\n'.format(
kwargs.get(ATTR_TITLE),
@ -76,5 +76,3 @@ class FileNotificationService(BaseNotificationService):
else:
text = '{}\n'.format(message)
file.write(text)
file.close()