[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

shelve.open call gives error

waltbrad

2/8/2008 8:37:00 AM

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.


7 Answers

jim-on-linux

2/8/2008 5:10:00 PM

0

On Friday 08 February 2008 03:36, waltbrad
wrote:
> 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://inq1ltd@inqvixta.com

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.

jim-on-linux

2/8/2008 5:20:00 PM

0

On Friday 08 February 2008 12:10,
jim-on-linux wrote:
> On Friday 08 February 2008 03:36, waltbrad
>
> wrote:
> > 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://inq1ltd@inqvixta.com
>
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.

jim-on-linux

2/8/2008 8:05:00 PM

0

On Friday 08 February 2008 03:36, waltbrad
wrote:
> 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://inq1ltyd@inqvista.com


#########
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

############





>
> 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.

Gabriel Genellina

2/8/2008 10:30:00 PM

0

En Fri, 08 Feb 2008 06:36:53 -0200, waltbrad <waltbrad@hotmail.com>
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.

--
Gabriel Genellina

waltbrad

2/9/2008 5:35:00 AM

0

On Feb 8, 5:29 pm, "Gabriel Genellina" <gagsl-...@yahoo.com.ar> wrote:
> En Fri, 08 Feb 2008 06:36:53 -0200, waltbrad <waltb...@hotmail.com>
> 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.
>
> --
> Gabriel Genellina

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.

Gabriel Genellina

2/10/2008 3:29:00 AM

0

En Sat, 09 Feb 2008 03:35:14 -0200, waltbrad <waltbrad@hotmail.com>
escribi�:

> On Feb 8, 5:29 pm, "Gabriel Genellina" <gagsl-...@yahoo.com.ar> wrote:
>> En Fri, 08 Feb 2008 06:36:53 -0200, waltbrad <waltb...@hotmail.com>
>> 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:
>>
>> shelve uses the anydbm module; anydbm tries to select the best database
>> module available, but apparently fails in your system.
>
> 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....

--
Gabriel Genellina

Bernie Woodham

2/10/2008 8:30:00 AM

0


"Gabriel Genellina" <gagsl-py2@yahoo.com.ar> wrote in message
news:mailman.571.1202614129.9267.python-list@python.org...
> En Sat, 09 Feb 2008 03:35:14 -0200, waltbrad <waltbrad@hotmail.com>
> escribi?:
>
>> On Feb 8, 5:29 pm, "Gabriel Genellina" <gagsl-...@yahoo.com.ar> wrote:
>>> En Fri, 08 Feb 2008 06:36:53 -0200, waltbrad <waltb...@hotmail.com>
>>> 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:
>>>
>>> shelve uses the anydbm module; anydbm tries to select the best database
>>> module available, but apparently fails in your system.
>>
>> 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....
>
> --
> Gabriel Genellina
>

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.