473,416 Members | 1,656 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

Error type for shelve.open()

I wanted to write the following code:

import shelve
try:
db = shelve.open(file, "r")
except SomeError:
print "Oh no, db not found"

Only, I'm not sure what SomeError should be. I tried error,
anydbm.error, shelve.open.anydb.error, etc. but can't find it. Things
worked fine with simply except:, but that's not optimal.

Does anyone know either the what the error is or where I can find it
for certain?

Thanks,
Martin

Jul 5 '06 #1
6 4407
ao******@gmail.com wrote:
I wanted to write the following code:

import shelve
try:
db = shelve.open(file, "r")
except SomeError:
print "Oh no, db not found"

Only, I'm not sure what SomeError should be. I tried error,
anydbm.error, shelve.open.anydb.error, etc. but can't find it. Things
worked fine with simply except:, but that's not optimal.

Does anyone know either the what the error is or where I can find it
for certain?

Thanks,
Martin
What error did you get with just the bare except?

you can find out by saying (for instance):
>>try:
1/0
except Exception, err:
E = err

>>E
<exceptions.ZeroDivisionError instance at 0xb6efd8cc>
or to get really fancy, use the traceback module
>>from traceback import format_exc
try:
1/0
except:
print format_exc()
Traceback (most recent call last):
File "<pyshell#10>", line 2, in ?
ZeroDivisionError: integer division or modulo by zero

Peace,
~Simon

Jul 6 '06 #2
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?

Thanks,
Martin
Simon Forman wrote:
ao******@gmail.com wrote:
I wanted to write the following code:

import shelve
try:
db = shelve.open(file, "r")
except SomeError:
print "Oh no, db not found"

Only, I'm not sure what SomeError should be. I tried error,
anydbm.error, shelve.open.anydb.error, etc. but can't find it. Things
worked fine with simply except:, but that's not optimal.

Does anyone know either the what the error is or where I can find it
for certain?

Thanks,
Martin

What error did you get with just the bare except?

you can find out by saying (for instance):
>try:
1/0
except Exception, err:
E = err

>E
<exceptions.ZeroDivisionError instance at 0xb6efd8cc>
or to get really fancy, use the traceback module
>from traceback import format_exc
try:
1/0
except:
print format_exc()
Traceback (most recent call last):
File "<pyshell#10>", line 2, in ?
ZeroDivisionError: integer division or modulo by zero

Peace,
~Simon
Jul 6 '06 #3
ao******@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

Jul 7 '06 #4
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:
ao******@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
Jul 7 '06 #5
I reported the bug to python.org and apparently it has already been
fixed in the latest SVN build :).
ao******@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:
ao******@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
Jul 10 '06 #6
ao******@gmail.com wrote:
I reported the bug to python.org and apparently it has already been
fixed in the latest SVN build :).
Awesome! Open Source at work! :D

Jul 10 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Kris Caselden | last post by:
Python's docs say that Shelve uses Pickle to serialize its data. However, I've noticed that Pickle can maintain internal links, while Shelve cannot. For instance: >>> d =...
0
by: ex laguna | last post by:
Hi, I have ran into a problem with py2exe 0.5.0 and shelve in python 2.3.3. The script works fine standalone, but not with py2exe. Does anyone have a solution of workaround for this? Thanks...
0
by: Glenn R Williams | last post by:
Has anybody gotten shelve to work under SuSE 9.1? I have SuSe 9.1, Python 2.3.3.85, db 4.2.52, and bsddb3-4.2.4. When I try to create a shelve, I get errors galore, Here's the traceback: ...
1
by: neutrinman | last post by:
why does the following error occur? def quit_time(): data_file = shelve.open("data.dat", "c") data_file = datetime.datetime.today() print data_file raw_input("enter") Traceback (most...
5
by: Philippe C. Martin | last post by:
Hi, I just installed (compiled) Python 2.4.2 under Suse 10. The following code generates a seg error: import shelve print shelve.open ('test') I assume this has to do with the db behind...
13
by: Sheldon | last post by:
Hi. Does anyone know if one can resume a python script at the error point after the error is corrected? I have a large program that take forever if I have to restart from scratch everytime. The...
13
by: 7stud | last post by:
test1.py: -------------------- import shelve s = shelve.open("/Users/me/2testing/dir1/aaa.txt") s = "red" s.close() --------output:------ $ python test1.py
1
by: max.aginaga | last post by:
Hi everyone I've come across the following problem: on two different linux machines, both running python 2.5 (r25:51908), I have the same file 'd.dat'. The md5 checksums are the same. Now, on...
1
by: Matthew Schibler | last post by:
I'm a newbie to Python, with some experience using perl (where I used nested arrays and hashes extensively). I am building a script in python for a MUD I play, and I want to use the shelve module...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.