[Tutor] string pickling and sqlite blob'ing

vince spicer vinces1979 at gmail.com
Wed Jun 24 19:49:10 CEST 2009


Pickle is more for storing complex objects (arrays, dict, etc). pickling a
string makes it bigger.

I have stored large text chunks in text and/or blob columns compressed with
gzip.zlib.compress and extracted with gzip.zlib.decompress

Comparison:

import cPickle as Pickle
import gzip

x = "asdfasdfasdfasdfasdfasdfasdfasdfasdf"

print len(x)
>> 36

print len(Pickle.dumps(x))
>> 44

print len(gzip.zlib.compress(x))
>> 14


Vince

On Wed, Jun 24, 2009 at 11:17 AM, Dinesh B Vadhia <dineshbvadhia at hotmail.com
> wrote:

>  I want to pickle (very long) strings and save them in a sqlite db.  The
> plan is to use pickle dumps() to turn a string into a pickle object and
> store it in sqlite.  After reading the string back from the sqlite db, use
> pickle loads() to turn back into original string.
>
> - Is this a good approach for storing very long strings?
>
> - Are the pickle'd strings stored in the sqlite db as a STRING or BLOB?
>
> Cheers.
>
> Dinesh
>
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090624/ae43beb3/attachment-0001.htm>


More information about the Tutor mailing list