By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,197 Members | 909 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,197 IT Pros & Developers. It's quick & easy.

Disappearing objects in shelve

P: n/a
I have read a number of threads relating to problems with shelve, but
I couldn't find one directly related my experience, so I would
appreciate some advice. The closest one ended with a recommendation
to upgrade to Python 2.3, but that, unfortunately, is out of my
control. The system I use runs Python 2.2.2, and whichdb gives

The problem only occurs when serializing class instances; lists don't
seem to be affected. Every time I attempt to read the instance from
the shelve file, it seems to delete it from the file even though I am
not performing any write operations. Attempts to use flag='r' in the generated error messages, as did restricting write
permissions to the database.

This is some example code. '' defines the class whose
instance is stored in db["john"], etc. The file, "editors.db",
originally contained keys "nick and "john". By the end, the file has
been emptied.

import shelve
import Editor

def main():
db ="editors.db")
value = db["john"]
print db.keys()

db ="editors.db")
value = db["nick"]
print db.keys()

import test

[ 'john','nick']

I got the same result when I attempted a deep copy instead of the
assignment to value. Anyone know what I'm missing?
Jul 18 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.