compressed serialization module
Mark
mseagoe at gmail.com
Mon Nov 17 22:13:12 EST 2008
On Nov 17, 3:08 pm, s... at pobox.com wrote:
> Mark> def saveOjb(self, dataObj):
> Mark> fName = self.version + '_' + self.modname + '.dat'
> Mark> f = open(fName, 'w')
> Mark> dStr = pickle.dumps(dataObj)
> Mark> c = dStr.encode("bz2")
> Mark> pickle.dump(c, f, pickle.HIGHEST_PROTOCOL)
> Mark> f.close()
>
> Hmmm... Why pickle it twice?
>
> def saveOjb(self, dataObj):
> fName = self.version + '_' + self.modname + '.dat'
> f = open(fName, 'wb')
> f.write(pickle.dumps(dataObj, pickle.HIGHEST_PROTOCOL).encode("bz2"))
> f.close()
>
> Skip
I wasn't sure whether the string object was still a string after
"encode" is called... at least whether it's still an ascii string.
And if not, whether it could be used w/ dumps. I tested your
variation and it works the same. I guess your "write" is doing the
same as my "dump", but may be more efficient. Thanks.
More information about the Python-list
mailing list