import os script_dir = os.path.dirname(os.path.abspath(__file__)) file_path = os.path.join(script_dir, 'json.txt') file_uuid = os.path.join(script_dir, 'pair_fig_uuid.txt') file_name = os.path.join(script_dir, 'pair_fig_name.txt') with open(file_path, encoding="utf-8") as f: card_json_txt = f.read() with open(file_uuid, encoding="cp932") as ff: fig_uuid = ff.read() with open(file_name, encoding="cp932") as ff: fig_name = ff.read() exchange_uuid = card_json_txt.replace('画像uuid', fig_uuid) exchange = exchange_uuid.replace('画像ファイル名', fig_name) output_path = os.path.join(script_dir, 'after_file_fig.txt') with open(output_path, 'w', encoding="utf-8") as out: out.write(exchange)