Saving pickled info and reloading info

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jun 2005
Posts: 146
Reputation: G-Do is an unknown quantity at this point 
Solved Threads: 28
G-Do's Avatar
G-Do G-Do is offline Offline
Junior Poster

Re: Saving pickled info and reloading info

 
0
  #11
Jun 16th, 2008
Hi count_chockula,

You can indeed edit a dictionary. You would load the dictionary with pickle.load(), then add a new key-value pair, then dump it again, like so:
  1. f = open("filename.txt", "r")
  2. d = pickle.load(f)
  3. f.close()
  4. d["new_key"] = "new_value"
  5. f = open("filename.txt", "w")
  6. pickle.dump(d, f)
  7. f.close()
Now filename.txt contains the same pickled dictionary from before, but with an addition.
Vi veri veniversum vivus vici
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC