With Python, can I keep a persistent dictionary and modify it?

snk picture snk · Aug 4, 2009 · Viewed 9.7k times · Source

So, I want to store a dictionary in a persistent file. Is there a way to use regular dictionary methods to add, print, or delete entries from the dictionary in that file?

It seems that I would be able to use cPickle to store the dictionary and load it, but I'm not sure where to take it from there.

Answer

Alex Martelli picture Alex Martelli · Aug 4, 2009

If your keys (not necessarily the values) are strings, the shelve standard library module does what you want pretty seamlessly.