generates (22, 'Invalid argument') Os X 10.5 with Python 2.5

seth hklasky at
Tue Feb 16 23:03:55 CET 2010

On Feb 14, 1:21 pm, a... at (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 it says:

"[, 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
writing. "

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, I am calling shelve.BsdDbShelf(bsddb3.btopen(filename,
'c')) filename, 'c', 2, writeback =
False )
        #hk 021010: need to use BsdDbShelf to ensure the usage of
bsddb3 on OsX 10.5 creates a bsddb185 file on OsX 10.5
        #but on OsX reads with bsddb3, who knows why...
        #as a result the throws
        #<class 'bsddb.error'> (22, 'Invalid argument')
        dbshelf=shelve.BsdDbShelf(bsddb3.btopen(filename, 'c'))

And that fixed on Os X 10.5. It also works fine on Windows, by
ensuring the proper import:
    import bsddb3
    import bsddb as bsddb3

More information about the Python-list mailing list