diff --git a/data_compression/huffman.py b/data_compression/huffman.py index 44eda6c03180..afe698e6dfe0 100644 --- a/data_compression/huffman.py +++ b/data_compression/huffman.py @@ -26,7 +26,7 @@ def parse_file(file_path: str) -> list[Letter]: frequencies, then convert the dict into a list of Letters. """ chars: dict[str, int] = {} - with open(file_path) as f: + with open(file_path, encoding="utf-8") as f: while True: c = f.read(1) if not c: @@ -78,7 +78,7 @@ def huffman(file_path: str) -> None: k: v for letter in traverse_tree(root, "") for k, v in letter.bitstring.items() } print(f"Huffman Coding of {file_path}: ") - with open(file_path) as f: + with open(file_path, encoding="utf-8") as f: while True: c = f.read(1) if not c: diff --git a/data_structures/arrays/sudoku_solver.py b/data_structures/arrays/sudoku_solver.py index d2fa43bbf298..c60ed535216c 100644 --- a/data_structures/arrays/sudoku_solver.py +++ b/data_structures/arrays/sudoku_solver.py @@ -206,7 +206,7 @@ def unitsolved(unit): def from_file(filename, sep="\n"): "Parse a file into a list of strings, separated by sep." - with open(filename) as file: + with open(filename, encoding="utf-8") as file: return file.read().strip().split(sep) diff --git a/searches/tabu_search.py b/searches/tabu_search.py index fd482a81224c..4759e629a7e7 100644 --- a/searches/tabu_search.py +++ b/searches/tabu_search.py @@ -49,7 +49,7 @@ def generate_neighbours(path): dict_of_neighbours = {} - with open(path) as f: + with open(path, encoding="utf-8") as f: for line in f: if line.split()[0] not in dict_of_neighbours: _list = [] @@ -88,7 +88,7 @@ def generate_first_solution(path, dict_of_neighbours): will travel, if he follows the path in first_solution. """ - with open(path) as f: + with open(path, encoding="utf-8") as f: start_node = f.read(1) end_node = start_node diff --git a/strings/detecting_english_programmatically.py b/strings/detecting_english_programmatically.py index e30e2ea8dd8b..efdcdca1857c 100644 --- a/strings/detecting_english_programmatically.py +++ b/strings/detecting_english_programmatically.py @@ -7,7 +7,7 @@ def load_dictionary() -> dict[str, None]: path = os.path.split(os.path.realpath(__file__)) english_words: dict[str, None] = {} - with open(path[0] + "/dictionary.txt") as dictionary_file: + with open(path[0] + "/dictionary.txt", encoding="utf-8") as dictionary_file: for word in dictionary_file.read().split("\n"): english_words[word] = None return english_words diff --git a/strings/word_patterns.py b/strings/word_patterns.py index ed603e9fefeb..0a47439b0a04 100644 --- a/strings/word_patterns.py +++ b/strings/word_patterns.py @@ -46,7 +46,7 @@ def get_word_pattern(word: str) -> str: import time start_time = time.time() - with open("dictionary.txt") as in_file: + with open("dictionary.txt", encoding="utf-8") as in_file: word_list = in_file.read().splitlines() all_patterns: dict = {}