[Lilug] python pickle compare files

Mike Costanzo quarsaw at gmail.com
Thu Mar 17 08:05:44 PDT 2016


Jorg,

I'm pretty sure that part of the implementation of the dict type in Python
is that there's no guarantee of order.  So if you serialize one you might
well get different output because the interpreter has the freedom to store
things however it wants for any given situation.

I haven't used it but there is an OrderedDict class that you can import
from the collections package (in Python 2.7)

https://docs.python.org/2/library/collections.html#collections.OrderedDict

If for some reason you're stuck with Python 2.6 *cough* *Red Hat 6* *cough*
 there's a link in that documentation section to a recipe that works in 2.4+

Hope that helps,

-Mike







On Thu, Mar 17, 2016 at 10:37 AM, Jorg Kewisch <jorg at bnl.gov> wrote:

> (pickle is a python function which allows writing complex data and meta
> data to a file and read it back)
>
> I have a dictionary in a pickle file. I read it with load() and write it
> into a second file with dump() without changing anything. The two files
> are different, it seems the sequence of the dictionary items differs.
> Why is that? And is there a simple way to compare the files?
>
> jorg
> _______________________________________________
> Lilug mailing list
> Lilug at lists.lilug.org
> http://lists.lilug.org/listinfo.cgi/lilug-lilug.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lilug.org/pipermail/lilug-lilug.org/attachments/20160317/016326e0/attachment.htm>


More information about the Lilug mailing list