Martin KellyThu Jul 6 22:09:03 PDT 2006
Okay... I haven't found a bug in python yet, but I guess I just found one. shelve works otherwise though... I've used it to save 10 or so variables, and it works correctly every time. I thought anydbm.error was the error, but I could never catch it... I see now that the reason was that I hadn't imported anydbm. I just tried and that works though, so thanks. I suppose I should submit a bug report now. Martin Bob Miller wrote: > Martin Kelly wrote: > >> I'm trying to figure out what error type is given by shelve.open(file, >> "r") when the file does not exist. > > The exception type is an anydbm.error. But I don't understand the > source code. > >>From anydbm.py: > > # ... > class error(Exception): > pass > # ... > error = tuple(_errors) > # ... line 77: > raise error, "need 'c' or 'n'..." > > The Python Reference Manual doesn't say anything about using a tuple > in a raise statement. > > http://docs.python.org/ref/raise.html > > But that's what it is. Here's a sample shell session. > > Python 2.4.3 (#1, Jun 28 2006, 06:34:30) > [GCC 3.4.6 (Gentoo 3.4.6-r1, ssp-3.4.5-1.0, pie-8.7.9)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> import shelve > >>> import anydbm > >>> try: > ... shelve.open('nonexistent', 'r') > ... except anydbm.error: > ... print 'caught it' > ... > caught it > Exception exceptions.AttributeError: "DbfilenameShelf instance has no > attribute 'writeback'" in ignored > >>> anydbm.error > (<class anydbm.error at 0xb7f48bfc>, > <class bsddb._db.DBError at 0xb7f5623c>, > <class gdbm.error at 0xb7f48cbc>, > <class dbm.error at 0xb7f5b38c>, > <class exceptions.IOError at 0xb7f774ac>) > >>> > > So, uh, what's that weird other bit, exceptions.AttributeError? > That's a bug in Python 2.4.3. You can see in shelve.py that > Shelf.__del__() calls Shelf.close() calls Shelf.sync() which > references self.writeback even though that attribute doesn't exist. > It also references self.dict which also doesn't exist. > > My opinion is that if shelve is that poorly debugged, it's probably > not ready for prime time. > > Or you could submit a bug report... >