my computer is allergic to pickles

Bob Fnord bob at example.com
Wed Mar 9 08:26:39 EST 2011


Miki Tebeka <miki.tebeka at gmail.com> wrote:

> > Or, which situations does shelve suit better and which does
> > marshal suit better?
> shelve ease of use and the fact it uses the disk to store objects makes it a good choice if you have a lot of object, each with a unique string key (and a tuple of strings can be converted to and from a string).
> 
> db = shelve.open("/tmp/foo.db")
> db["key1"] = (1, 2, 3)
> ...
> 
> Marshal is faster and IIRC more geared toward network operations. But I haven't used it that much ...

>From looking at the shelve info in the library reference, I get
the impression it's tricky to change the values in the dict for
existing keys and be sure they get changed on disk. My dict lists
of strings and integers as values and the lists get changed as
the program analyzes the input files, then stored on disk in
their final form. I guess marshal is better for that.

How can you convert a tuple of strings to a string and back in a
reliable deterministic way? The original strings may have ' " ,
in them.




More information about the Python-list mailing list