Error type for shelve.open()

aomighty at gmail.com aomighty at gmail.com
Mon Jul 10 03:04:19 EDT 2006


I reported the bug to python.org and apparently it has already been
fixed in the latest SVN build :).
aomighty at gmail.com wrote:
> Yes, the problem was that I hadn't imported anydbm.error... it's
> working now.
>
> As for the AttributeError at the end, I talked to someone else, and he
> looked at the source and said it was a bug in shelve. I think I will
> report it to python.org.
>
> Anyway, thanks :).
> Simon Forman wrote:
> > aomighty at gmail.com wrote:
> > > I tried what you said and it looked like maybe AttributeError, but that
> > > didn't work either.
> > >
> > > This code snippet:
> > >
> > > import shelve
> > > from traceback import format_exc
> > >
> > > try:
> > >    db = shelve.open("meh", "r")
> > > except:
> > >    print format_exc()
> > >
> > > Gave me this output:
> > > Traceback (most recent call last):
> > >   File "test.py", line 5, in ?
> > >     db = shelve.open("meh", "r")
> > >   File "/usr/lib/python2.4/shelve.py", line 231, in open
> > >     return DbfilenameShelf(filename, flag, protocol, writeback, binary)
> > >   File "/usr/lib/python2.4/shelve.py", line 212, in __init__
> > >     Shelf.__init__(self, anydbm.open(filename, flag), protocol,
> > > writeback, binary)
> > >   File "/usr/lib/python2.4/anydbm.py", line 77, in open
> > >     raise error, "need 'c' or 'n' flag to open new db"
> > > error: need 'c' or 'n' flag to open new db
> > >
> > > Exception exceptions.AttributeError: "DbfilenameShelf instance has no
> > > attribute 'writeback'" in  ignored
> > >
> > > Do you know what the error is?
> >
> > No.  If you tried catching AttributeError and it didn't work then I'd
> > guess that the AttributeError is a secondary result of the initial
> > error.
> >
> > This part of the traceback,
> >
> > >   File "/usr/lib/python2.4/anydbm.py", line 77, in open
> > >     raise error, "need 'c' or 'n' flag to open new db"
> > > error: need 'c' or 'n' flag to open new db
> >
> > indicates that some sort of custom error, probably defined in the
> > anydbm.py module.
> >
> > Catching the execption and binding it to a var,
> >
> > >>> try:
> > ...     db = shelve.open("meh", "r")
> > ... except Exception, err:
> > ...     E = err
> > ...
> > Exception exceptions.AttributeError: "DbfilenameShelf instance has no
> > attribute 'writeback'" in  ignored
> > >>> E
> > <anydbm.error instance at 0xb7d8270c>
> >
> >
> >
> > So:
> > >>> from anydbm import error
> > >>> try:
> > ...     db = shelve.open("meh", "r")
> > ... except error:
> > ...     print 'Aha!  got it!'
> > ...
> > Aha!  got it!
> > Exception exceptions.AttributeError: "DbfilenameShelf instance has no
> > attribute 'writeback'" in  ignored
> >
> >
> > Well, that catches the error, but I don't know what's going on with the
> > additional AttributeError or what to do about it.
> > 
> > Peace,
> > ~Simon




More information about the Python-list mailing list