From f176dd002784adc1a65a47ffddaea8a7fca073b3 Mon Sep 17 00:00:00 2001 From: IsxImattI Date: Mon, 11 Nov 2024 00:23:37 +0100 Subject: [PATCH] context manager for file handling changed too in from_file function --- data_structures/arrays/sudoku_solver.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/data_structures/arrays/sudoku_solver.py b/data_structures/arrays/sudoku_solver.py index 1b2eb0f6f..81cc2ee13 100644 --- a/data_structures/arrays/sudoku_solver.py +++ b/data_structures/arrays/sudoku_solver.py @@ -171,7 +171,8 @@ def solved(values): def from_file(filename, sep="\n"): "Parse a file into a list of strings, separated by sep." - return open(filename).read().strip().split(sep) + with open(filename) as file: + return file.read().strip().split(sep) def random_puzzle(assignments=17):