Unshelving the data?

U

Uncle Ben

Shelving is a wonderfully simple way to get keyed access to a store of
items. I'd like to maintain this cache though.

Is there any way to remove a shelved key once it is hashed into the
system? I could do it manually by removing the value and erasing the
key in the directory list. But is there a more elegant way?

Or should I to go the full database route? It is not a lage
application.

Ben
 
C

Chris Torek

Shelving is a wonderfully simple way to get keyed access to a store of
items. I'd like to maintain this cache though.

Is there any way to remove a shelved key once it is hashed into the
system?

$ pydoc shelve
....
To summarize the interface (key is a string, data is an arbitrary
object):
...
d[key] = data # store data at key (overwrites old data if
# using an existing key)
data = d[key] # retrieve a COPY of the data at key (raise
# KeyError if no such key) -- NOTE that this
# access returns a *copy* of the entry!
del d[key] # delete data stored at key (raises KeyError
# if no such key)
...

Seems pretty straightforward. :) Are you having some sort
of problem with "del"?
 
A

Adam Tauno Williams

Shelving is a wonderfully simple way to get keyed access to a store of
items. I'd like to maintain this cache though.
+1

Is there any way to remove a shelved key once it is hashed into the
system? I could do it manually by removing the value and erasing the
key in the directory list. But is there a more elegant way?

del shelve[key]
Or should I to go the full database route? It is not a lage
application.

Stick with shelves. Much simpler.
 
U

Uncle Ben

Shelving is a wonderfully simple way to get keyed access to a store of
items. I'd like to maintain this cache though.
+1

Is there any way to remove a shelved key once it is hashed into the
system?  I could do it manually by removing the value and erasing the
key in the directory list. But is there a more elegant way?

del shelve[key]
Or should I to go the full database route?  It is not a lage
application.

Stick with shelves.  Much simpler.

Thanks. And Chris, thanks for showing me 'pyco'. I had looked in six
thick books and had not found anything on removing keys.

Ben
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,778
Messages
2,569,605
Members
45,238
Latest member
Top CryptoPodcasts

Latest Threads

Top