当您说“主存储器”时,您是指硬盘吗?计算机中只有一个内存系统。
您可以使用pickle模块将 Python 数据对象写入文件。我不确定您是否可以将多个对象腌制到一个文件中,但这应该无关紧要。
import pickle
def dump_dict(dict, name):
with open(name, 'wb') as file:
return pickle.dump(file, dict)
def get_dict(name):
with open(name, 'rb') as file:
return pickle.load(file)
def get_key(key, *list_of_dicts):
"""The first argument is the key; any further args are interpreted as the names of
pickled dict files to check."""
out = []
for name in *list_of_dicts:
with open(name, 'rb') as f:
out.append(pickle.load(f).get(key)) # Add this dict's value, glossing over KeyErrors.
return tuple(out)
您当然可以找出其余部分并根据需要扩展功能。