我已经仔细阅读了Python文档提供的信息,但仍然有些困惑。有人可以张贴示例代码来编写新文件,然后使用pickle将字典转储到其中吗?
尝试这个:
import pickle a = {'hello': 'world'} with open('filename.pickle', 'wb') as handle: pickle.dump(a, handle, protocol=pickle.HIGHEST_PROTOCOL) with open('filename.pickle', 'rb') as handle: b = pickle.load(handle) print a == b