[Python] Finding an error name
Martin Kelly
aomighty at gmail.com
Thu Jul 6 19:10:01 PDT 2006
I'm trying to figure out what error type is given by shelve.open(file,
"r") when the file does not exist. I've tried everything that looks
likely, but none of them seem to work. (This is for use in a try:
except: statement). So for now it's working fine with an except:, but
that's not optimal... it will catch all errors and it would be better to
be more specific.
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
Does anyone know what the error might be?
Thanks,
Martin
More information about the Python
mailing list