compressed serialization module

Nick Craig-Wood nick at craig-wood.com
Mon Nov 17 15:29:57 EST 2008


skip at pobox.com <skip at pobox.com> wrote:
> 
>      >> I used pickle and found the file was saved in text format.  I wonder
>      >> whether anyone is familiar with a good compact off-the-shelf module
>      >> available that will save in compressed format... or maybe an opinion
>      >> on a smart approach for making a custom one?
> 
>      Joe> Well, here's a thought: create a zip file (using the standard
>      Joe> zipfile module), and pickle your data into that.
> 
>  Also, specify a pickle binary protool.  Here's a silly example:
> 
>      >>> len(pickle.dumps([1,2,3], pickle.HIGHEST_PROTOCOL))
>      14
>      >>> len(pickle.dumps([1,2,3], 0))
>      18

Or even

>>> L = range(100)
>>> a = pickle.dumps(L)
>>> len(a)
496
>>> b = a.encode("bz2")
>>> len(b)
141
>>> c = b.decode("bz2")
>>> M = pickle.loads(c)
>>> M == L
True
>>>  


-- 
Nick Craig-Wood <nick at craig-wood.com> -- http://www.craig-wood.com/nick



More information about the Python-list mailing list