Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #90041 > unrolled thread
| Started by | pra devOPS <siv.devops@gmail.com> |
|---|---|
| First post | 2015-05-05 12:55 -0700 |
| Last post | 2015-05-08 11:22 +0000 |
| Articles | 4 — 3 participants |
Back to article view | Back to comp.lang.python
Json Comaprision pra devOPS <siv.devops@gmail.com> - 2015-05-05 12:55 -0700
Re: Json Comaprision John Gordon <gordon@panix.com> - 2015-05-06 16:27 +0000
Re: Json Comaprision pra devOPS <siv.devops@gmail.com> - 2015-05-26 05:57 -0700
Re: Json Comaprision Denis McMahon <denismfmcmahon@gmail.com> - 2015-05-08 11:22 +0000
| From | pra devOPS <siv.devops@gmail.com> |
|---|---|
| Date | 2015-05-05 12:55 -0700 |
| Subject | Json Comaprision |
| Message-ID | <mailman.164.1430902487.12865.python-list@python.org> |
[Multipart message — attachments visible in raw view] — view raw
Hi All: I wanted to compare two json files ignoring few of the keys in the json files. Can anybody suggest me few things? Thanks, Siva
[toc] | [next] | [standalone]
| From | John Gordon <gordon@panix.com> |
|---|---|
| Date | 2015-05-06 16:27 +0000 |
| Message-ID | <midfe5$ma7$1@reader1.panix.com> |
| In reply to | #90041 |
In <mailman.164.1430902487.12865.python-list@python.org> pra devOPS <siv.devops@gmail.com> writes: > I wanted to compare two json files ignoring few of the keys in the json > files. > Can anybody suggest me few things? Load each json file into a python object, delete the keys you don't care about, and compare the two objects. -- John Gordon Imagine what it must be like for a real medical doctor to gordon@panix.com watch 'House', or a real serial killer to watch 'Dexter'.
[toc] | [prev] | [next] | [standalone]
| From | pra devOPS <siv.devops@gmail.com> |
|---|---|
| Date | 2015-05-26 05:57 -0700 |
| Message-ID | <mailman.53.1432645042.5151.python-list@python.org> |
| In reply to | #90064 |
[Multipart message — attachments visible in raw view] — view raw
Hey all thanks for the answers, I am done wiht the same . Sorry fore delayed replied On Wed, May 6, 2015 at 9:27 AM, John Gordon <gordon@panix.com> wrote: > In <mailman.164.1430902487.12865.python-list@python.org> pra devOPS < > siv.devops@gmail.com> writes: > > > I wanted to compare two json files ignoring few of the keys in the json > > files. > > > Can anybody suggest me few things? > > Load each json file into a python object, delete the keys you don't care > about, and compare the two objects. > > -- > John Gordon Imagine what it must be like for a real medical doctor > to > gordon@panix.com watch 'House', or a real serial killer to watch > 'Dexter'. > > -- > https://mail.python.org/mailman/listinfo/python-list >
[toc] | [prev] | [next] | [standalone]
| From | Denis McMahon <denismfmcmahon@gmail.com> |
|---|---|
| Date | 2015-05-08 11:22 +0000 |
| Message-ID | <mii68r$olm$8@dont-email.me> |
| In reply to | #90041 |
On Tue, 05 May 2015 12:55:20 -0700, pra devOPS wrote: > I wanted to compare two json files ignoring few of the keys in the json > files. > > Can anybody suggest me few things? json files usually get imported to either a list or a dictionary (unless they're a simple string or number). If the files are json arrays they'll get imported as lists. otherwise if they're key:value pairs they'll get imported as a dictionary. Basically you need a routine that can take two arbitrary objects, check if they're the same data type, and then check their values. If they're of a collection type, checking their values means recursively checking that every element in the collection matches in type and value. You need to be able to handle lists, dictionaries, strings, ordinals and floats, and for floats you might want to consider that if two floats are generated by two different systems, perhaps a cray xmp running compiled fortran and an acorn risc os box running compiled c++ for example, they might disagree at the least significant digit but still be considered equal for your purposes. It's much easier to prove things are different than to prove they are the same, and you're much more likely to falsely detect difference than you are to correctly detect equality as the complexity of the objects you are checking increases unless you get the code right. For a list, you need to consider if the order of elements is important. If not, then for every element in list a you need to detect if an identical element is in list b. Supposing you have two lists of lists. This might mean that for every sub list in a, you need to check every sub list in b to see if it matches. You probably also want to check for lists and dictionaries if the sizes are equivalent too. Here's an example why: a = [ [a,b,c] ] b = [ [a,b,c], [a,c,b], [b,a,c], [b,c,a], [c,a,b], [c,b,a] ] If you compare sublists purely on the basis that they contain the same elements, then a[0] == each of b[0..5] Does that make a and b equal? -- Denis McMahon, denismfmcmahon@gmail.com
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web