Compare recursively objects
bogus at bogus.net
Wed Mar 17 17:33:41 CET 2004
"Nicolas Fleury" <nid_oizo at yahoo.com_remove_the_> wrote in message
news:gF_5c.6730$kc2.158843 at nnrp1.uunet.ca...
> Do you know if the use of pickle would work? If I dump two objects and
> compare the files, do I have the assurance that the files are the same
> if the recursive members are the same?
I am not very familiar with pickle, other than its purpose for persisting
object representations for later reconstitution. Given that, I suspect your
pickle-to-file-and-compare-the-files scheme would work.
However, I would be wary of a scheme that routinely used files for
temporary/scratch storage in this manner. There are just too many ordinary
ways for this to go wrong:
- disk has insufficient room to create files
- insufficient user privs to create files
- trying to create files in non-existent or protected directory
- program exits before scratch files get cleaned up, leaving behind growing
- concurrent users end up using each others' files by mistake; accidentally
creating duplicate scratch file names
Plus, file i/o is just plain agonizingly slow.
In sum, I suspect you will get diverted to dealing with a whole bunch of
issues that are artifacts of using files, when what you really wanted to do
is compare some objects. Perhaps you could pickle to a string and compare
the strings? At least this avoids most of the file system complications.
More information about the Python-list