Python:使用Pickle保存字典

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python:使用Pickle保存字典相关的知识,希望对你有一定的参考价值。

  1. import pickle
  2.  
  3. zoit = { "Crud": "No", "Fsck": "Blox"}
  4. file = open("pickle.pck", "w") # write mode
  5. pickle.dump(zoit, file)
  6.  
  7. print "Written to disk. Deleting 'zoit' now."
  8. del zoit
  9. file.close()
  10. del file
  11. print "Zoit is now deleted. Reading back from file now:"
  12.  
  13. file = open("pickle.pck", "r") # read mode
  14. narf = pickle.load(file)
  15. print narf

以上是关于Python:使用Pickle保存字典的主要内容,如果未能解决你的问题,请参考以下文章

python保存字典和读取字典pickle

Python列表/字典的保存与加载(pickle)

Python入门--17--pickle

python ,json,pickle 模块

第九节:python pickle序列化装饰器模块

Python中Pickle模块的dump()方法和load()方法