import re import json # 加载测试数据 def load_test_data(file_path): test_data = [] try: with open(file_path, 'r', encoding='utf-8') as file: for line in file: test_data.append(json.loads(line.strip())) except Exception as e: print(f"加载测试数据时发生错误: {e}") return test_data # 保存提交结果 def save_submissions_to_jsonl(submissions, output_file_path): try: with open(output_file_path, 'w', encoding='utf-8') as file: for submission in submissions: json.dump(submission, file, ensure_ascii=False) file.write('\n') print(f"提交的结果已保存到 {output_file_path}") except Exception as e: print(f"保存提交结果时发生错误: {e}") # 检测答案中的选项 def detect_choice_in_answer(answer_text): possible_choices = ['A', 'B', 'C', 'D'] for choice in possible_choices: if re.search(rf'(?= 3: code_block = parts[1].strip() # 提取第一个 ``` 和第二个 ``` 之间的部分 # 如果代码块中包含 "python\n",则删除它 if "python\n" in code_block: code_block = code_block.replace("python\n", "") return code_block else: return "" # 如果没有找到成对的 ```,返回空字符串