From ffe2fae8bfe4ce2651dcd013a4546a6b53e18a58 Mon Sep 17 00:00:00 2001 From: Wilbur Jaywright Date: Sat, 27 Apr 2024 22:36:46 -0400 Subject: [PATCH] Fixed bug in __mass_add_words() Context manager cannot accept NoneType. Close file manually. --- bookworm_wordlist_editor.pyw | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/bookworm_wordlist_editor.pyw b/bookworm_wordlist_editor.pyw index 88029b7..6793cef 100644 --- a/bookworm_wordlist_editor.pyw +++ b/bookworm_wordlist_editor.pyw @@ -535,13 +535,15 @@ class Editor(Tk): """Add a whole file's worth of words""" #Open and read a file with a human-readable list of new words - with filedialog.askopenfile(title = "Select human-readable list of words", filetypes = [("Plain text", "*.txt")]) as f: - #The user cancelled via the open file dialog - if not f: - return + f = filedialog.askopenfile(title = "Select human-readable list of words", filetypes = [("Plain text", "*.txt")]) + + #The user cancelled via the open file dialog + if not f: + return - #Read the file - text = f.read().strip() + #Read and close the file + text = f.read().strip() + f.close() #filter file to only letters and spaces alpha_text = "".join([c for c in text if c.lower() in bw.ALPHABET or c.isspace()])