Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Shelve or pickle module

77 views
Skip to first unread message

Guillaume Bog

unread,
May 17, 2008, 11:14:19 PM5/17/08
to pytho...@python.org
Hello,

I read and re-read "Python in a Nutshell" written by Alex Martelli,
who knows what he is talking about. I'm a bit new to python and I'm
going to start doing persistence side on a project. Martelli's book
seems to tell me that I should use shelve module, but any code I
browsed is using pickle instead. Is there any reason to prefer pickle
over shelve?

Thanks,

Gabriel Genellina

unread,
May 18, 2008, 12:45:57 AM5/18/08
to pytho...@python.org

A shelve is just a persistent dictionary that uses pickle to store the objects.
If you want to store one or a few objects, using pickle directly may be easier.
Any problem you may have with pickle (nonpickleable objects, security risks) will happen with shelve too.

--
Gabriel Genellina

Ville M. Vainio

unread,
May 18, 2008, 11:54:38 AM5/18/08
to
"Gabriel Genellina" <gags...@yahoo.com.ar> writes:


> A shelve is just a persistent dictionary that uses pickle to store
> the objects. If you want to store one or a few objects, using
> pickle directly may be easier. Any problem you may have with pickle
> (nonpickleable objects, security risks) will happen with shelve too.

Shameless plug warning!

If you want to store pickles "directly" in a directory with
shelve-like dict API, you may also be interested in my "pickleshare"
module:

http://pypi.python.org/pypi/pickleshare/0.3

0 new messages