473,739 Members | 7,416 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Error type for shelve.open()

I wanted to write the following code:

import shelve
try:
db = shelve.open(fil e, "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.any db.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 4445
ao******@gmail. com wrote:
I wanted to write the following code:

import shelve
try:
db = shelve.open(fil e, "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.any db.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.Zer oDivisionError 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#1 0>", line 2, in ?
ZeroDivisionErr or: 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("me h", "r")
except:
print format_exc()

Gave me this output:
Traceback (most recent call last):
File "test.py", line 5, in ?
db = shelve.open("me h", "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(fil ename, 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.Attr ibuteError: "DbfilenameShel f 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(fil e, "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.any db.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.Zer oDivisionError 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#1 0>", line 2, in ?
ZeroDivisionErr or: 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("me h", "r")
except:
print format_exc()

Gave me this output:
Traceback (most recent call last):
File "test.py", line 5, in ?
db = shelve.open("me h", "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(fil ename, 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.Attr ibuteError: "DbfilenameShel f 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("me h", "r")
.... except Exception, err:
.... E = err
....
Exception exceptions.Attr ibuteError: "DbfilenameShel f instance has no
attribute 'writeback'" in ignored
>>E
<anydbm.error instance at 0xb7d8270c>

So:
>>from anydbm import error
try:
.... db = shelve.open("me h", "r")
.... except error:
.... print 'Aha! got it!'
....
Aha! got it!
Exception exceptions.Attr ibuteError: "DbfilenameShel f 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("me h", "r")
except:
print format_exc()

Gave me this output:
Traceback (most recent call last):
File "test.py", line 5, in ?
db = shelve.open("me h", "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(fil ename, 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.Attr ibuteError: "DbfilenameShel f 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("me h", "r")
... except Exception, err:
... E = err
...
Exception exceptions.Attr ibuteError: "DbfilenameShel f instance has no
attribute 'writeback'" in ignored
>E
<anydbm.error instance at 0xb7d8270c>

So:
>from anydbm import error
try:
... db = shelve.open("me h", "r")
... except error:
... print 'Aha! got it!'
...
Aha! got it!
Exception exceptions.Attr ibuteError: "DbfilenameShel f 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("me h", "r")
except:
print format_exc()
>
Gave me this output:
Traceback (most recent call last):
File "test.py", line 5, in ?
db = shelve.open("me h", "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(fil ename, 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.Attr ibuteError: "DbfilenameShel f 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("me h", "r")
... except Exception, err:
... E = err
...
Exception exceptions.Attr ibuteError: "DbfilenameShel f instance has no
attribute 'writeback'" in ignored
>>E
<anydbm.error instance at 0xb7d8270c>

So:
>>from anydbm import error
>>try:
... db = shelve.open("me h", "r")
... except error:
... print 'Aha! got it!'
...
Aha! got it!
Exception exceptions.Attr ibuteError: "DbfilenameShel f 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
6745
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 = shelve.open('shelvedata.txt',writeback=True) >>> d= >>> d=d >>> print d {'a': , 'b': } >>> d=2 >>> print d {'a': , 'b': }
0
2033
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 much. # Begin of setup.py from distutils.core import setup import py2exe setup(console=)
0
1300
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: Traceback (most recent call last): File "<pyshell#17>", line 1, in -toplevel- d=shelve.open('mydbm',flag='c') File "/usr/lib/python2.3/shelve.py", line 231, in open
1
5915
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 recent call last):
5
1336
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 shelve.
13
1746
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 error was the data writing a file so it seemed such a waste if all the data was lost and must be recalculated again. Sincerely, Sheldon
13
6512
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
4647
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 one machine the following code works while on the other...
1
4585
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 to store persistent information between script executions. The following code does not work for me, import shelve, sys, os, string db = shelve.open(os.path.abspath(os.path.dirname(sys.argv)) + '/' + 'sandbox.dat', 'c') db = 'apple'
0
9341
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9269
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8216
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6756
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6056
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4572
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4826
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2748
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2195
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.