From 3d86409f759f656858fa06b2de16c5b6d632fd82 Mon Sep 17 00:00:00 2001 From: vangef Date: Thu, 24 Oct 2024 22:57:20 +0100 Subject: [PATCH] fix encoding error when assignment name has an emoji (or unicode, in general) --- utils/inspector.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/inspector.py b/utils/inspector.py index 2b66f3e..51b47c5 100644 --- a/utils/inspector.py +++ b/utils/inspector.py @@ -54,7 +54,7 @@ def generate_hashes_gradebook(gradebook_dir_path: str) -> str: # main function csv_file_name = f'{gradebook_dir_name}_gradebook_file_hashes_{datetime.now().strftime("%Y%m%d-%H%M%S")}.csv' csv_file_path = os.path.join(CSV_DIR, csv_file_name) - with open(csv_file_path, 'w', newline='') as csvfile: # open the output CSV file for writing + with open(csv_file_path, 'w', newline='', encoding='utf-8') as csvfile: # open the output CSV file for writing fieldnames = ['Student ID', 'filename', 'sha256 hash'] writer = csv.DictWriter(csvfile, fieldnames=fieldnames) writer.writeheader() @@ -86,7 +86,7 @@ def generate_hashes_submissions(submissions_dir_path: str) -> str: # main funct csv_file_name = f'{submissions_dir_name}_submissions_file_hashes_{datetime.now().strftime("%Y%m%d-%H%M%S")}.csv' csv_file_path = os.path.join(CSV_DIR, csv_file_name) - with open(csv_file_path, 'w', newline='') as csvfile: # open the output CSV file for writing + with open(csv_file_path, 'w', newline='', encoding='utf-8') as csvfile: # open the output CSV file for writing fieldnames = ['Student ID', 'filepath', 'filename', 'sha256 hash'] writer = csv.DictWriter(csvfile, fieldnames=fieldnames) writer.writeheader()