Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #46164
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder5.xlned.com!news2.euro.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <avnesh.nitk@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.006 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'json': 0.07; 'subject:file': 0.07; 'subject:two': 0.07; 'string': 0.09; 'naturally': 0.09; 'required,': 0.09; 'subject:using': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'def': 0.12; 'file;': 0.16; 'newlines': 0.16; 'so)': 0.16; 'sorting': 0.16; 'subject:compare': 0.16; 'unordered': 0.16; 'subject:python': 0.16; 'ignore': 0.16; 'wrote:': 0.18; 'file,': 0.19; 'value.': 0.19; 'example': 0.22; 'import': 0.22; 'email addr:gmail.com>': 0.22; 'python?': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'mon,': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; '>': 0.26; 'compare': 0.26; 'header:In-Reply-To:1': 0.27; 'idea': 0.28; 'am,': 0.29; 'database,': 0.30; 'message- id:@mail.gmail.com': 0.30; 'url:mailman': 0.30; 'extract': 0.31; 'file': 0.32; 'text': 0.33; 'url:python': 0.33; 'not.': 0.33; 'could': 0.34; 'etc': 0.35; 'operations': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'add': 0.35; 'there': 0.35; 'really': 0.36; 'data,': 0.36; 'url:listinfo': 0.36; 'doing': 0.36; 'thanks': 0.36; 'subject:?': 0.36; 'hi,': 0.36; 'url:org': 0.36; 'two': 0.37; 'skip:o 20': 0.38; 'depends': 0.38; 'files': 0.38; 'issue': 0.38; 'fact': 0.38; 'does': 0.39; 'changed': 0.39; 'url:mail': 0.40; 'how': 0.40; 'read': 0.60; 'new': 0.61; 'skip:n 10': 0.64; 'to:addr:gmail.com': 0.65; 'here': 0.66; 'approaches': 0.68; 'actually,': 0.84; 'way...': 0.84; 'good,': 0.91; 'notion': 0.91; 'rusi': 0.91; '2013': 0.98 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=dDIKub+lPsKj/fibwsBqqhW2fNE93G7XciquHW0zexk=; b=x5C2fOj41xRHFQj6r7olCi7xPRWTJnjyjg81h+gixUyaoTpobz3QrCBIRrzQzZ97yR 40OxW2qHrQAFh0TZ125HfIDynwgxH26KSeDHuYunRkKZ6JYvCIx5a2IxCJ2ub/YsZlCf Xo+OOOu3DbLBWmWhsxM1sxmoUpcCE7Jq+QwbJyabaJ+NXextTWPU6HvL2Cxyg8QAKhvM /oPfqDbQLKXY13H2lPbzHqHgtX001KAAKEtphyqoY2VWB97t6l4YdXr3ta3W5Pj+8YzO YNNYzvCoIRhTnNRNeB4dsUAXoigghbgxYIhgclw5hlpNCDm/BHg2Kt9+2QkyU/M3KCtT xu2A== |
| MIME-Version | 1.0 |
| X-Received | by 10.50.176.164 with SMTP id cj4mr4201808igc.66.1369631139123; Sun, 26 May 2013 22:05:39 -0700 (PDT) |
| In-Reply-To | <bb5d992b-4592-4777-ae47-3b3e090703a1@d8g2000pbe.googlegroups.com> |
| References | <355f934e-bda0-4316-96bb-583c498ecb1a@googlegroups.com> <bb5d992b-4592-4777-ae47-3b3e090703a1@d8g2000pbe.googlegroups.com> |
| Date | Mon, 27 May 2013 10:35:39 +0530 |
| Subject | Re: how to compare two json file line by line using python? |
| From | Avnesh Shakya <avnesh.nitk@gmail.com> |
| To | rusi <rustompmody@gmail.com> |
| Content-Type | multipart/alternative; boundary=089e0111d68485a62904ddac1959 |
| Cc | python-list@python.org |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2230.1369631143.3114.python-list@python.org> (permalink) |
| Lines | 120 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1369631143 news.xs4all.nl 15945 [2001:888:2000:d::a6]:33651 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:46164 |
Show key headers only | View raw
[Multipart message — attachments visible in raw view] - view raw
Actually, I am extracting data from other site in json format and I want to
put it in my database and when I extract data again then I want to compare
last json file, if these are same then no issue otherwise i will add new
data in database, so here may be every time data can be changed or may be
not so I think sorting is required, but if i compare line by line that will
be good, I am thinking in this way...
On Mon, May 27, 2013 at 10:21 AM, rusi <rustompmody@gmail.com> wrote:
> On May 27, 9:32 am, Avnesh Shakya <avnesh.n...@gmail.com> wrote:
> > hi,
> > how to compare two json file line by line using python? Actually I am
> doing it in this way..
> >
> > import simplejson as json
> > def compare():
> > newJsonFile= open('newData.json')
> > lastJsonFile= open('version1.json')
> > newLines = newJsonFile.readlines()
> > print newLines
> > sortedNew = sorted([repr(x) for x in newJsonFile])
> > sortedLast = sorted([repr(x) for x in lastJsonFile])
> > print(sortedNew == sortedLast)
> >
> > compare()
> >
> > But I want to compare line by line and value by value. but i found that
> json data is unordered data, so how can i compare them without sorting it.
> please give me some idea about it. I am new for it.
> > I want to check every value line by line.
> >
> > Thanks
>
> It really depends on what is your notion that the two files are same
> or not.
>
> For example does extra/deleted non-significant white-space matter?
>
> By and large there are two approaches:
> 1. Treat json as serialized python data-structures, (and so) read in
> the data-structures into python and compare there
>
> 2. Ignore the fact that the json file is a json file; just treat it as
> text and use string compare operations
>
> Naturally there could be other considerations: the files could be huge
> and so you might want some hybrid of json and text approaches
> etc etc
> --
> http://mail.python.org/mailman/listinfo/python-list
>
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
how to compare two json file line by line using python? Avnesh Shakya <avnesh.nitk@gmail.com> - 2013-05-26 21:32 -0700
Re: how to compare two json file line by line using python? rusi <rustompmody@gmail.com> - 2013-05-26 21:51 -0700
Re: how to compare two json file line by line using python? Avnesh Shakya <avnesh.nitk@gmail.com> - 2013-05-27 10:35 +0530
Re: how to compare two json file line by line using python? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-05-27 05:33 +0000
Re: how to compare two json file line by line using python? Avnesh Shakya <avnesh.nitk@gmail.com> - 2013-05-27 11:58 +0530
Re: how to compare two json file line by line using python? Grant Edwards <invalid@invalid.invalid> - 2013-05-28 16:00 +0000
Re: how to compare two json file line by line using python? Denis McMahon <denismfmcmahon@gmail.com> - 2013-05-27 10:50 +0000
csiph-web