shelve.open call gives error

W

waltbrad

Working through the Mark Lutz book Programming Python 3rd Edition.

A couple of modules in the "Preview" chapter give me errors. Both on a
shelve.open call:

Pretty simple code, (2nd example):
=====code begin=====
import shelve
from people import Person, Manager

bob = Person('Bob Smith', 42, 30000, 'sweng')
sue = Person('Sue Jones', 45, 40000, 'music')
tom = Manager('Tom Doe', 50, 50000)

db = shelve.open('class-shelve')
db['bob'] = bob
db['sue'] = sue
db['tom'] = tom
db.close()
====code end====

Error message++++++++
Traceback (most recent call last):
File "make_db_classes.py", line 9, in <module>
db = shelve.open('class-shelve')
File "C:\PYTHON25\lib\shelve.py", line 225, in open
return DbfilenameShelf(filename, flag, protocol, writeback)
File "C:\PYTHON25\lib\shelve.py", line 209, in __init__
Shelf.__init__(self, anydbm.open(filename, flag), protocol,
writeback)
File "C:\PYTHON25\lib\anydbm.py", line 83, in open
return mod.open(file, flag, mode)
File "C:\PYTHON25\lib\dbhash.py", line 16, in open
return bsddb.hashopen(file, flag, mode)
File "C:\PYTHON25\lib\bsddb\__init__.py", line 306, in hashopen
d.open(file, db.DB_HASH, flags, mode)
bsddb.db.DBError: (5, 'Input/output error')
++++++++++End Error message

I've looked on the errata pages of his website and used Google to find
someone else who ran into this problem. Found someone else who had a
similar error but no explanation was given. No other reader of the
book seems to have had the problem.

I'm using 2.5.1

I thought maybe the file had to exist before it could be opened, so I
created one with that name, but no dice. A different but similar set
of errors. I also thought maybe there had to be a second argument
like 'a', 'r' or 'w'. That doesn't work either.

This is the first chapter of the book. It's an overview of the
language features. So, this is pretty perplexing. Any help would be
appreciated. Thanks.
 
J

jim-on-linux

Working through the Mark Lutz book
Programming Python 3rd Edition.

A couple of modules in the "Preview"
chapter give me errors. Both on a
shelve.open call:

Pretty simple code, (2nd example):


from;
jim-on-linux
http://[email protected]

My guess,
add this and see if it helps
=====code begin=====
import dbhash
import shelve
from people import Person, Manager

bob = Person('Bob Smith', 42, 30000,
'sweng') sue = Person('Sue Jones', 45,
40000, 'music') tom = Manager('Tom Doe',
50, 50000)

db = shelve.open('class-shelve')
db['bob'] = bob
db['sue'] = sue
db['tom'] = tom
db.close()
====code end====

Error message++++++++
Traceback (most recent call last):
File "make_db_classes.py", line 9, in
<module> db = shelve.open('class-shelve')
File "C:\PYTHON25\lib\shelve.py", line
225, in open return
DbfilenameShelf(filename, flag, protocol,
writeback) File
"C:\PYTHON25\lib\shelve.py", line 209, in
__init__ Shelf.__init__(self,
anydbm.open(filename, flag), protocol,
writeback)
File "C:\PYTHON25\lib\anydbm.py", line
83, in open return mod.open(file, flag,
mode) File "C:\PYTHON25\lib\dbhash.py",
line 16, in open return
bsddb.hashopen(file, flag, mode) File
"C:\PYTHON25\lib\bsddb\__init__.py", line
306, in hashopen d.open(file, db.DB_HASH,
flags, mode) bsddb.db.DBError: (5,
'Input/output error') ++++++++++End Error
message

I've looked on the errata pages of his
website and used Google to find someone
else who ran into this problem. Found
someone else who had a similar error but
no explanation was given. No other reader
of the book seems to have had the problem.

I'm using 2.5.1

I thought maybe the file had to exist
before it could be opened, so I created
one with that name, but no dice. A
different but similar set of errors. I
also thought maybe there had to be a
second argument like 'a', 'r' or 'w'. That
doesn't work either.

This is the first chapter of the book.
It's an overview of the language features.
So, this is pretty perplexing. Any help
would be appreciated. Thanks.
 
J

jim-on-linux

from;
jim-on-linux
http://[email protected] My guess,
add this and see if it helps

also try import anydbm if not on linux,
or import dbhash will work on linux
=====code begin=====

import dbhash
import shelve
from people import Person, Manager

bob = Person('Bob Smith', 42, 30000,
'sweng') sue = Person('Sue Jones', 45,
40000, 'music') tom = Manager('Tom Doe',
50, 50000)

db = shelve.open('class-shelve')
db['bob'] = bob
db['sue'] = sue
db['tom'] = tom
db.close()
====code end====

Error message++++++++
Traceback (most recent call last):
File "make_db_classes.py", line 9, in
<module> db =
shelve.open('class-shelve') File
"C:\PYTHON25\lib\shelve.py", line 225,
in open return
DbfilenameShelf(filename, flag,
protocol, writeback) File
"C:\PYTHON25\lib\shelve.py", line 209,
in __init__ Shelf.__init__(self,
anydbm.open(filename, flag), protocol,
writeback)
File "C:\PYTHON25\lib\anydbm.py", line
83, in open return mod.open(file, flag,
mode) File "C:\PYTHON25\lib\dbhash.py",
line 16, in open return
bsddb.hashopen(file, flag, mode) File
"C:\PYTHON25\lib\bsddb\__init__.py",
line 306, in hashopen d.open(file,
db.DB_HASH, flags, mode)
bsddb.db.DBError: (5, 'Input/output
error') ++++++++++End Error message

I've looked on the errata pages of his
website and used Google to find someone
else who ran into this problem. Found
someone else who had a similar error but
no explanation was given. No other
reader of the book seems to have had the
problem.

I'm using 2.5.1

I thought maybe the file had to exist
before it could be opened, so I created
one with that name, but no dice. A
different but similar set of errors. I
also thought maybe there had to be a
second argument like 'a', 'r' or 'w'.
That doesn't work either.

This is the first chapter of the book.
It's an overview of the language
features. So, this is pretty perplexing.
Any help would be appreciated. Thanks.
 
J

jim-on-linux

Working through the Mark Lutz book
Programming Python 3rd Edition.

A couple of modules in the "Preview"
chapter give me errors. Both on a
shelve.open call:

Pretty simple code, (2nd example):
=====code begin=====
import shelve
from people import Person, Manager

bob = Person('Bob Smith', 42, 30000,
'sweng') sue = Person('Sue Jones', 45,
40000, 'music') tom = Manager('Tom Doe',
50, 50000)

db = shelve.open('class-shelve')
db['bob'] = bob
db['sue'] = sue
db['tom'] = tom
db.close()
====code end====


This works for me.
I converted your numbers to text,
I believe shelves requires string keys and
values.
I had to eliminate the import Person, Manager

If you still have problems you have an idea
where to look.

jim-on-linux
http://[email protected]


#########
import shelve
##from people import Person, Manager

bob = 'Bob Smith', '42, 30000', 'sweng'
sue = 'Sue Jones', '45, 40000', 'music'
tom = 'Tom Doe', '50, 50000'

db = shelve.open('class-shelve')
db['bob'] = bob
db['sue'] = sue
db['tom'] = tom
db.close

############
 
G

Gabriel Genellina

Working through the Mark Lutz book Programming Python 3rd Edition.

A couple of modules in the "Preview" chapter give me errors. Both on a
shelve.open call:

Pretty simple code, (2nd example):
=====code begin=====
import shelve
from people import Person, Manager

bob = Person('Bob Smith', 42, 30000, 'sweng')
sue = Person('Sue Jones', 45, 40000, 'music')
tom = Manager('Tom Doe', 50, 50000)

db = shelve.open('class-shelve')
db['bob'] = bob
db['sue'] = sue
db['tom'] = tom
db.close()
====code end====

shelve uses the anydbm module; anydbm tries to select the best database
module available, but apparently fails in your system. If you are just
learning Python, I don't think it's worth trying to fix it; instead, let's
force anydbm to use the fallback module dumbdbm (implemented in pure
python, slow, but bullet-proof, or at least arrow-proof :) )

Add these two lines at the start of your script:

import dumbdbm, anydbm
anydbm._defaultmod = dumbdbm

Remove the class-shelve.* files, if any, before running it.
 
W

waltbrad

En Fri, 08 Feb 2008 06:36:53 -0200, waltbrad <[email protected]>
escribió:


Working through the Mark Lutz book Programming Python 3rd Edition.
A couple of modules in the "Preview" chapter give me errors. Both on a
shelve.open call:
Pretty simple code, (2nd example):
=====code begin=====
import shelve
from people import Person, Manager
bob = Person('Bob Smith', 42, 30000, 'sweng')
sue = Person('Sue Jones', 45, 40000, 'music')
tom = Manager('Tom Doe', 50, 50000)
db = shelve.open('class-shelve')
db['bob'] = bob
db['sue'] = sue
db['tom'] = tom
db.close()
====code end====

shelve uses the anydbm module; anydbm tries to select the best database
module available, but apparently fails in your system. If you are just
learning Python, I don't think it's worth trying to fix it; instead, let's
force anydbm to use the fallback module dumbdbm (implemented in pure
python, slow, but bullet-proof, or at least arrow-proof :) )

Add these two lines at the start of your script:

import dumbdbm, anydbm
anydbm._defaultmod = dumbdbm

Remove the class-shelve.* files, if any, before running it.

Thanks to all for the help, but the only advice that worked was
Gabriel's.

I actually tried to look into the issue of fixing it, but I'm just too
much of a novice.

I put the two lines in a seperate module that I import to save typing.

But as I gain experience I'd like to return to this issue and try to
fix it. Can you give me advice on how to go about that?

I'm working on a win98 system. I have python on a linux system,
(Kubuntu) and winxp but it's more convenient right now for me to use
the 98 laptop.
 
G

Gabriel Genellina

But as I gain experience I'd like to return to this issue and try to
fix it. Can you give me advice on how to go about that?

I'm working on a win98 system. I have python on a linux system,
(Kubuntu) and winxp but it's more convenient right now for me to use
the 98 laptop.

I've tried the example on WinXP and it runs fine. Looks like the bsddb
package isn't working on Windows98; I don't know if that platform is still
supported or not. Try submitting a bug report http://bugs.python.org
 
B

Bernie Woodham

Gabriel Genellina said:
I've tried the example on WinXP and it runs fine. Looks like the bsddb
package isn't working on Windows98; I don't know if that platform is still
supported or not. Try submitting a bug report http://bugs.python.org

Yeah, I think you're right. I also have no problems with it on XP.

5.1 is supposed to be the last version that get win9x support.

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top