Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #25616 > unrolled thread

Which lib can diff two dict tree?

Started byesbatmop@gmail.com
First post2012-07-19 02:51 -0700
Last post2012-07-19 17:17 -0700
Articles 2 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  Which lib can diff two dict tree? esbatmop@gmail.com - 2012-07-19 02:51 -0700
    Re: Which lib can diff two dict tree? alex23 <wuwei23@gmail.com> - 2012-07-19 17:17 -0700

#25616 — Which lib can diff two dict tree?

Fromesbatmop@gmail.com
Date2012-07-19 02:51 -0700
SubjectWhich lib can diff two dict tree?
Message-ID<b2000e25-8a8e-44bc-9895-9b406265578e@googlegroups.com>
Q1:
dict a:{'a1': 'b1', 'a2': {'b2': 'c2'}, 'a3': 'b3'}
dict b:{'a1': 'b1', 'a2': {'b2': 'c3'}}
which lib can diff two dict tree?
like:
print struct_diff(a,b)
>>tree 'a3'
print value_diff(a,b)
>>c3

Q2
How can I diff two json file?How can I get struct_diff and value_diff?

Q3
How can I diff two xml file? How can I get struct_diff and value_diff?

[toc] | [next] | [standalone]


#25661

Fromalex23 <wuwei23@gmail.com>
Date2012-07-19 17:17 -0700
Message-ID<c5f96ea5-1806-49ee-8b0e-5e7049416be6@nw7g2000pbb.googlegroups.com>
In reply to#25616
On Jul 19, 7:51 pm, esbat...@gmail.com wrote:
> Q1:
> which lib can diff two dict tree?
> Q2
> How can I diff two json file?How can I get struct_diff and value_diff?
> Q3
> How can I diff two xml file? How can I get struct_diff and value_diff?

Rather than trying to come up with a method for finding the diffs of
three different data structures, it might be easier to transform all
the structures into the same form and then just use one mechanism for
diffs.

There's a 3rd-party python library for producing diffs of XML
documents:
http://www.logilab.org/projects/xmldiff

Python dicts can be converted to XML using one of the suggestions
here:
http://stackoverflow.com/questions/1019895/serialize-python-dictionary-to-xml

JSON can be transformed into dicts by using the standard library's
json module.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web