10.09添加git

This commit is contained in:
Cricial
2025-10-09 13:36:20 +08:00
commit 91f2122b65
95 changed files with 39866 additions and 0 deletions

29
11.py Normal file
View File

@@ -0,0 +1,29 @@
import pickle
import os
from 查看进度 import visualize_progress
def load_cached_data(file_path):
"""
从指定的缓存文件加载数据。
如果文件不存在或加载失败,则返回空字典。
"""
if not os.path.exists(file_path):
print(f"Warning: Cache file '{file_path}' does not exist.")
return {}
try:
with open(file_path, 'rb') as f:
data = pickle.load(f)
print(f"Successfully loaded cache from '{file_path}'.")
return data
except (pickle.UnpicklingError, FileNotFoundError, EOFError) as e:
print(f"Error loading cache from '{file_path}': {e}")
return {}
# 示例用法
# data_dct = load_cached_data("G_Firm_add_edges.pkl")
visualize_progress()