Zlib-error

Fredrik Lundh fredrik at pythonware.com
Mon Nov 22 10:16:29 EST 1999


Thomas Weholt <thomas at bibsyst.no> wrote:
> data_to_store = pickle.dumps(object)
> data_to_store = zlib.compress(data)
> db = shelve.open('test','cwr')
> db[id] = data_to_store
> db.close()
> 
> and later :
> 
> data = zlib.decompress(pickle.loads(db[id]))
> 
> the error occurs.

maybe you should decompress the data
*before* unpickling it?  like this:

    data = pickle.loads(zlib.decompress(db[id]))

(btw, note that shelve pickles the string you
store in the database.  if you're compressing
all items in the database, you can save a few
more bytes by using anydbm instead of shelve).

</F>





More information about the Python-list mailing list