| | import pandas as pd |
| | import os |
| | import difflib |
| |
|
| | |
| | input_text = "TypeError: unsupported operand type(s) for ^: 'int' and 'float'" |
| | demo_code_folder = './' |
| |
|
| | errorType = pd.read_excel('./错误类型.xlsx') |
| | type = [] |
| | for i in range(len(errorType)): |
| | information = { |
| | 'num': int(errorType['number'][i]), |
| | 'type': errorType['type'][i], |
| | 'context': errorType['context'][i] |
| | } |
| | type.append(information) |
| |
|
| | |
| | best_match = None |
| | best_similarity = 0 |
| | for info in type: |
| | similarity = difflib.SequenceMatcher(None, input_text, info['type']).ratio() |
| | if similarity > best_similarity: |
| | best_similarity = similarity |
| | best_match = info |
| |
|
| | |
| | if best_match: |
| | print(f"存在的错误为:{best_match['context']}") |
| | code_file_name = str(best_match['num']) + ".py" |
| | code_file_path = os.path.join(demo_code_folder, code_file_name) |
| | |
| | if os.path.exists(code_file_path): |
| | |
| | with open(code_file_path, "r") as file: |
| | code = file.read() |
| | print(f"示例代码:\n{code}") |
| | else: |
| | print("未找到对应的示例代码文件") |
| | else: |
| | print("未找到相似的错误类型") |
| |
|
| |
|
| |
|