shelve portability problem

nadim_ghaznavi at my-deja.com nadim_ghaznavi at my-deja.com
Thu Jul 29 14:25:20 EDT 1999


I'm having a problem moving a Python shelve ODB from Solaris to Linux.
Here's some sample code to demo the problem:

On the Solaris Platform:

# python
Python 1.5.2 (#1, Jun  5 1999, 15:51:52)  [GCC 2.8.1] on sunos5
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> import shelve
>>> friends = ['Jane','Jan','Simon']
>>> odb = shelve.open('odbfile')
>>> odb['foo']=friends
>>> odb.close()

Which leaves me with two files:
# ls -l
-rw-r--r--   1 root     other          0 Jul 29 13:50 odbfile.dir
-rw-r--r--   1 root     other       1024 Jul 29 13:57 odbfile.pag

To confirm that all is well, lets have a look at the data again:
On Solaris:

# python
Python 1.5.2 (#1, Jun  5 1999, 15:51:52)  [GCC 2.8.1] on sunos5
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> import shelve
>>> samedb = shelve.open('odbfile')
>>> buddies = samedb['foo']
>>> buddies
['Jane', 'Jan', 'Simon']
>>> samedb.close()

As expected, the data is still in the odb.  Next we'll move the
odbfile.dir and odbfile.pag to the Linux platform (I used FTP, nothing
strange there).

# ls -l
-rw-r--r--   1 root     root            0 Jul 29 13:59 odbfile.dir
-rw-r--r--   1 root     root         1024 Jul 29 13:59 odbfile.pag
# python
Python 1.5.1 (#1, Mar 21 1999, 22:49:36)  [GCC egcs-2.91.66 19990314/Li
on linux-i386
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>>  import shelve
>>> nodb = shelve.open('odbfile')
>>> nodb.keys()
[]
>>> nodb.close()
>>>
# ls -l
-rw-r--r--   1 root     root         4096 Jul 29 14:00 odbfile
-rw-r--r--   1 root     root            0 Jul 29 13:59 odbfile.dir
-rw-r--r--   1 root     root         1024 Jul 29 13:59 odbfile.pag

What seems to be happening is that Solaris is storing the data in an old
DBM style database, and Linux is using a new gdbm format.  When I try
opening the old Solaris ODB, python incorrectly opens a new gdbm ODB
instead.

A couple of things to note:  I do have the free gdbm package installed
on my solaris platform (even though Python isn't using it):

# pkginfo GNUgdbm
application GNUgdbm        gdbm

I know I can work around this by using pickle and a specific DB module,
but does anyone know how I can get it working using the shelve module?

	Nadim




Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.




More information about the Python-list mailing list