import os #-------------------------------------------------------------------------------------------------------- #-------------------------------------------------------------------------------------------------------- #-------------------------------------------------------------------------------------------------------- #-------------------------------------------------------------------------------------------------------- #------------------------ 更新修改后的内容到原始列表 ------------------------------------ #-------------------------------------------------------------------------------------------------------- #-------------------------------------------------------------------------------------------------------- #-------------------------------------------------------------------------------------------------------- #-------------------------------------------------------------------------------------------------------- # 从文本文件加载数据 def load_from_file(file_path): with open(file_path, "r") as f: content = f.read().strip() # 读取并去除首尾空白字符 return [int(x) for x in content.split(",") if x.strip()] # 过滤空字符串并转换为整数 # 从文本文件更新字典内容 def update_dict_from_files(data_update, directory): for key in data_update.keys(): file_path = os.path.join(directory, f"{key}.txt") if os.path.exists(file_path): data_update[key] = load_from_file(file_path) print(f"已更新 {key} 的数据") else: print(f"文件 {file_path} 不存在,跳过") # 返回更新后点的字典 return data_update if __name__ == '__main__': update_dict_from_files()