shelve.open generates (22, 'Invalid argument') Os X 10.5 with Python 2.5
hklasky at gmail.com
Tue Feb 16 23:03:55 CET 2010
On Feb 14, 1:21 pm, a... at pythoncraft.com (Aahz) wrote:
> Nope -- any reason you can't change the filename?
Os X 10.5 did not recognized the dbm extension.
But, I have been able to fix the problem (hope it helps somebody):
At http://docs.python.org/library/shelve.html it says:
"shelve.open(filename[, flag='c'[, protocol=None[,
Open a persistent dictionary. The filename specified is the base
filename for the underlying database. As a side-effect, an extension
may be added to the filename and more than one file may be created. By
default, the underlying database file is opened for reading and
Then, I went ahead and try to find out which type of db file was being
print whichdb.whichdb(dbmFile)#prints bsddb185
kpfmac:xLPR kpf$ python
Python 2.5.1 (r251:54863, Feb 9 2009, 18:49:36)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import bsddb185
<bsddb.bsddb object at 0x12260>
I found that the dbm extension is generated by bsddb and bsddb3 so I
went ahead and installed it: sudo easy_install bsddb3.
Finally, in our code, I just went ahead and instead of using
shelve.open, I am calling shelve.BsdDbShelf(bsddb3.btopen(filename,
#realizations=shelve.open( filename, 'c', 2, writeback =
#hk 021010: need to use BsdDbShelf to ensure the usage of
bsddb3 on OsX 10.5
#shelve.open creates a bsddb185 file on OsX 10.5
#but shelve.open on OsX reads with bsddb3, who knows why...
#as a result the shelve.open throws
#<class 'bsddb.error'> (22, 'Invalid argument')
And that fixed on Os X 10.5. It also works fine on Windows, by
ensuring the proper import:
import bsddb as bsddb3
More information about the Python-list