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


Groups > comp.lang.python > #46380

Re: detect key conflict in a JSON file

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder1.xlned.com!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <airween@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.060
X-Spam-Evidence '*H*': 0.90; '*S*': 0.02; 'package,': 0.03; 'duplicate': 0.07; 'json': 0.07; 'subject:file': 0.07; 'cc:addr :python-list': 0.11; 'python': 0.11; 'dictionary,': 0.16; 'modul': 0.16; 'started?': 0.16; 'subject:key': 0.16; 'yaml': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'first.': 0.19; 'import': 0.22; 'python?': 0.22; 'cc:addr:python.org': 0.22; 'cc:2**1': 0.23; 'header:User-Agent:1': 0.23; 'library,': 0.24; 'second': 0.26; 'header:In-Reply-To:1': 0.27; "i'm": 0.30; 'struct': 0.31; 'probably': 0.32; 'linux': 0.33; 'no,': 0.35; 'but': 0.35; '+0200,': 0.36; 'thanks': 0.36; 'files': 0.38; 'how': 0.40; 'read': 0.60; 'skip:y 20': 0.60; 'most': 0.60; 'ago,': 0.61; 'from:charset:utf-8': 0.61; 'content-disposition:inline': 0.62; 'real': 0.63; 'different': 0.65; 'to:addr:gmail.com': 0.65; 'here': 0.66; 'hints': 0.68; 'silently': 0.84; 'received:86': 0.91; 'choice.': 0.93; 'lot,': 0.93; 'received:hu': 0.93; '2013': 0.98
X-Spam-Flag NO
X-Spam-Score -1.892
X-Spam-Level
X-Spam-Status No, score=-1.892 tagged_above=-20 required=4 tests=[ALL_TRUSTED=-1, AWL=0.106, BAYES_00=-1.9, DKIM_ADSP_CUSTOM_MED=0.001, FREEMAIL_FROM=0.001, NML_ADSP_CUSTOM_MED=0.9] autolearn=no
Date Wed, 29 May 2013 16:04:00 +0200
From Ervin Hegedüs <airween@gmail.com>
To Jabba Laci <jabba.laci@gmail.com>
Subject Re: detect key conflict in a JSON file
References <mailman.2347.1369826248.3114.python-list@python.org> <roy-5C9415.09253929052013@news.panix.com> <CAOuJsMkzEZGEK0gVDMYNk3y3PDgn7+nYxwur_U6=_kaUMKSGUw@mail.gmail.com>
MIME-Version 1.0
Content-Type text/plain; charset=utf-8
Content-Disposition inline
In-Reply-To <CAOuJsMkzEZGEK0gVDMYNk3y3PDgn7+nYxwur_U6=_kaUMKSGUw@mail.gmail.com>
User-Agent Mutt/1.5.20 (2009-06-14)
Cc Python mailing list <python-list@python.org>, Roy Smith <roy@panix.com>
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.2359.1369836452.3114.python-list@python.org> (permalink)
Lines 45
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1369836452 news.xs4all.nl 15916 [2001:888:2000:d::a6]:49649
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:46380

Show key headers only | View raw


Hello,

On Wed, May 29, 2013 at 03:41:50PM +0200, Jabba Laci wrote:
> > The real answer here is that JSON is probably not the best choice for
> > large files that get hand-edited.  For data that you intend to hand-edit
> > a lot, YAML might be a better choice.
> >
> >> Currently the value of the second key silently overwrites the value of
> >> the first.
> 
> Thanks but how would it be different with YAML? Can YAML check duplicate keys?

no, I think it can't,

I'm using yaml a few months ago, as I noticed, the last key
prevail.


> How to process (read) YAML files in Python? Can you give me some hints
> how to get started? All I need is read it in and create a dictionary
> of it.


import yaml


struct = yaml.load(file("yamlfile.yml" 'r'))



and struct will be a Python dictionary,



As I know, yaml modul is not part of standard Python library, but
most Linux systems has package, eg. Debian/Ubuntu has a
"python-yaml".



Cheers:


a.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

detect key conflict in a JSON file Jabba Laci <jabba.laci@gmail.com> - 2013-05-29 13:16 +0200
  Re: detect key conflict in a JSON file Roy Smith <roy@panix.com> - 2013-05-29 09:25 -0400
    Re: detect key conflict in a JSON file Jabba Laci <jabba.laci@gmail.com> - 2013-05-29 15:41 +0200
      Re: detect key conflict in a JSON file rusi <rustompmody@gmail.com> - 2013-05-29 07:36 -0700
    Re: detect key conflict in a JSON file Ervin Hegedüs <airween@gmail.com> - 2013-05-29 16:04 +0200
    Re: detect key conflict in a JSON file Roy Smith <roy@panix.com> - 2013-05-29 11:20 -0400
      Re: detect key conflict in a JSON file Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-05-30 03:10 +0000

csiph-web