這裏假設題目裏面提到的”單獨兩個JSON文件的比較方法“的函數是compare_two_files,它接受兩個文件的文件名作為參數。
from pathlib import Path
def compare_two_folders(from_folder, to_folder):
from_folder = Path(from_folder)
to_folder = Path(to_folder)
for json_file in from_folder.glob('*.json'):
json_file_name = json_file.name
json_file_to_compare = to_folder / f'a{json_file_name}'
compare_tow_files(json_file, json_file_to_compare)