Python: using Pickle to save a dictionary


/ Published in: Python
Save to your folder(s)



Copy this code and paste it in your HTML
  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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.