[Tutor] using shelve

chrispython at mac.com chrispython at mac.com
Fri Jun 22 03:59:16 CEST 2007

I created a shelf called 'myshelf' and put two objects in it, a string and a list. When I open the shelf I get:

>>> d=shelve.open('/Users/development/Desktop/myshelf')
>>> d.keys()
['dir1', 'dir2']
>>> d
{'dir2': '/Users/development/Desktop/RSSReaderApp/RSS.db', 'dir1': ['.DS_Store', '.localized', 'access the latest version', 'Python Quick Reference.webloc', 'rssdb', 'workspace']}

It seems that when you use shelve.open(), it actually brings the entire shelf dictionary into memory, accessible through d.

What if you had 100 objects in myshelf, or 1000 or 100,000? Wouldn't it get bogged down?

If so, what is it good for and how would you store a large number of objects? (Storing strings and lists in an sql database is probably the way to go for this simple example, but what if  you had more complex objects?)

Chris V.

More information about the Tutor mailing list