From c7f9f06f720ec57d3a7cbe4b19f420ee13c2343a Mon Sep 17 00:00:00 2001 From: Ivan Habunek Date: Thu, 2 Feb 2023 09:45:36 +0100 Subject: [PATCH] Use context for writing to file --- toot/tui/overlays.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/toot/tui/overlays.py b/toot/tui/overlays.py index f31e57c..9c33310 100644 --- a/toot/tui/overlays.py +++ b/toot/tui/overlays.py @@ -42,9 +42,8 @@ class StatusSource(urwid.Padding): def save_json(self): filename = self.filename_edit.get_text()[0][10:] # skip "Filename: " if filename: - f = open(filename, "w") - f.write(self.source) - f.close() + with open(filename, "w") as f: + f.write(self.source) self.status_text.set_text(("footer_message", f"Saved to {filename}"))