Save a single result with incremental updates
(filename: str, result: Dict)
| 258 | |
| 259 | |
| 260 | def save_result(filename: str, result: Dict): |
| 261 | """Save a single result with incremental updates""" |
| 262 | results = [] |
| 263 | if os.path.exists(filename): |
| 264 | try: |
| 265 | with open(filename, 'r') as f: |
| 266 | results = json.load(f) |
| 267 | except (FileNotFoundError, json.JSONDecodeError): |
| 268 | results = [] |
| 269 | |
| 270 | results.append(result) |
| 271 | |
| 272 | with open(filename, 'w') as f: |
| 273 | json.dump(results, f, indent=2) |
| 274 | |
| 275 | |
| 276 | def load_existing_results(filename: str) -> List[Dict]: |