[Tutor] need advice about a dictionary ({})

Alan Gauld alan.gauld at btinternet.com
Sun Sep 11 02:34:18 CEST 2011


On 11/09/11 00:18, Richard D. Moores wrote:

>> So you open the file and from that point on treat it exactly like a
>> dictionary.
>
> I'm still a bit shaky about dictionaries.

But you started the post with using a dictionary.

Shelve is just a dictionary that lives in a file instead of memory.
If you can put data into or read it out of a dictionary then you can do 
the same with shelve.

The only complexity is you have to open the file before sing it and 
close it when your done.

> Much of what comes after that is beyond me.


> Thanks for your encouragement Alan, but I'm still looking among my
> Python books for a good exposition of shelve.

You probably won't find much in books because shelve has such a specific 
purpose. As a result there isn't much to say about it
if you've already covered dictionaries.

It's a file based dictionary. So read up on dictionaries.
Then just use it.

There are a few limitations with shelve but for most normal
cases you can ignore that and just use it like any normal
dictionary.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/



More information about the Tutor mailing list