From 6cc3031572dbc82cee0c6606da8bdd88bd43cde7 Mon Sep 17 00:00:00 2001 From: KIM HYOJUNG Date: Wed, 19 Nov 2025 19:13:33 +0900 Subject: [PATCH] Fix path_to_file_list and write_file_list --- main.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index 0d1f17b..ee66901 100644 --- a/main.py +++ b/main.py @@ -2,7 +2,8 @@ def path_to_file_list(path: str) -> List[str]: """Reads a file and returns a list of lines in the file""" - li = open(path, 'w') + with open(path, 'r', encoding='utf-8') as f: + lines = [line.rstrip('\n') for line in f] return lines def train_file_list_to_json(english_file_list: List[str], german_file_list: List[str]) -> List[str]: @@ -33,9 +34,9 @@ def process_file(file): def write_file_list(file_list: List[str], path: str) -> None: """Writes a list of strings to a file, each string on a new line""" - with open(path, 'r') as f: - for file in file_list: - f.write('\n') + with open(path, 'w', encoding='utf-8') as f: + for line in file_list: + f.write(line + '\n') if __name__ == "__main__": path = './'