pickle, cPickle, zlib, and the future

Tim Peters tim.one at comcast.net
Sat Mar 2 01:14:09 EST 2002


[Scott Gilbert]
> ...
> So can I rely on the first character 'x' being reserved for zlib, and
> cPickle/pickle strings never starting with 'x'?

I sure wouldn't.

> ...
> (BTW: In cases somebody asks why I don't just prefix my dump strings
> saying where they came from: The dumps can be rather large (maybe 10's
> of megabytes), and I really don't want to have to create a multiple
> megabyte substring from the original.)

This part I didn't follow.  Surely you're writing your dumps to a file? 

f.write('pick') - or - f.write('zlib')
f.write(the_dump_string)

when writing then

dumpkind = f.read(4)
if dumpkind == 'pick':
    # read next pickle from f
elif dumpkind == 'zlib':
    # let zlib chew on the next part
else:
    # etc

when reading.  A parallel file of kind-codes also comes to mind.  Etc.




More information about the Python-list mailing list