dbm interoperability between Perl and Python?

Roy Smith roy at panix.com
Tue Jan 29 20:07:45 CET 2002


-- Skip Montanaro <skip at pobox.com> wrote:
> Sounds like good old fashioned dbm files.  On my linux system the dbm
> library seems to create Berkeley DB 1.85 files (must be a linker issue).
> Try this on your Solaris system:
>
>     import dbm
>     db = dbm.open("tmp/foo", "c")
>     db['a'] = 'sdfsdfsdf'
>     db.close()
>
> and see what kind(s) of file(s) get created.

Yes, I get .dir/.pag files on Solaris.

I think I see what the problem is.  It seems like the behavior of whichdb() 
changed between python 2.0 (which is on my linux box) and 2.1 (which I have 
on solaris).  The old way, you gave whichdb() the full name of the file:

Python 2.0.1 (#1, Oct 27 2001, 20:47:54)
[GCC egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)] on linux2
[...]
>>> whichdb.whichdb ("OBJBYOID.db")
'dbhash'
>>> whichdb.whichdb ("OBJBYOID")
>>>

But the new module seems to only want the base name of the file:

Python 2.1.1 (#1, Dec  2 2001, 18:57:39)
[GCC 3.0.1] on sunos5
[...]
>>> whichdb.whichdb ("OBJBYOID.dir")
''
>>> whichdb.whichdb ("OBJBYOID")
'dbm'
>>>

Anydbm.open() has the same behavior.  On 2.0.1, you do anydbm.open 
("file.db"), but on 2.1.1, it's anydbm.open ("file").  The documentation 
for either version doesn't really say one way or the other.  The 2.1 way is 
arguably the "correct" way, though.


--
Roy Smith
roy at panix.com





More information about the Python-list mailing list