BLU Discuss list archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Discuss] Application config files
- Subject: [Discuss] Application config files
- From: gaf at gapps.blu.org (Jerry Feldman)
- Date: Fri, 12 Jul 2019 17:30:46 -0400
- In-reply-to: <20190712211615.GB31101@bladeshadow.org>
- References: <CAEvgogF9s200fVh_HaO2dHnmVV94vJ4gSSaWWOCj+YwN1mFMGw@mail.gmail.com> <20190712174001.zf5gvwbpfsqlkqjh@randomstring.org> <20190712140720.38215f7c@mydesk.domain.cxm> <20190712211615.GB31101@bladeshadow.org>
Big advantage here is that it also somewhat forces a better structure on the code. I keep a lot of my data in dictionaries also. On Fri, Jul 12, 2019 at 5:17 PM Derek Martin <invalid at pizzashack.org> wrote: > On Fri, Jul 12, 2019 at 02:07:20PM -0400, Steve Litt wrote: > > On Fri, 12 Jul 2019 13:40:01 -0400 > > Dan Ritter <dsr at randomstring.org> wrote: > > > > > Jerry Feldman wrote: > > > > I have an application that I wrote where I am using a .ini style > > > > file for config. I chose that as an afterthought but maybe JSON, > > > > YAML, or TOML might be better formats. > > > JSON is out from the get-go: It's not meant to be read and written by > > humans. > > I largely disagree. If it's currently in INI format the equivalent > JSON should generally be perfectly human-readable, e.g.: > > { > "thingy": { > "name": "foo", > "ip": "10.1.2.3", > "value": 1, > "live": true, > "notes": null > } > } > > Here, "thingy" would be equivalent to your [section] and then its > fields are the name-value pairs of that section. > > The advantages of JSON are that it's pretty ubiquitous, there are > parsers to read and write the file available already in pretty much > every language, so it's less code you have to write and test yourself, > and if you ever want to switch languages this is a non-issue. Plus, > the code needed to parse the file is generally trivial, especially in > Python. > > >>> import json > >>> data = ''' > ... { > ... "thingy": { > ... "name": "foo", > ... "ip": "10.1.2.3", > ... "value": 1, > ... "live": true, > ... "notes": null > ... } > ... } > ... ''' > >>> parsed = json.loads(data) > >>> parsed > {u'thingy': {u'notes': None, u'ip': u'10.1.2.3', u'live': True, > u'name': u'foo', u'value': 1}} > >>> print parsed["thingy"]["name"] > foo > > Of course, Python can do any of the mentioned options, so if you're > sure you'll stick with that, it probably really doesn't matter. > > -- > Derek D. Martin http://www.pizzashack.org/ GPG Key ID: 0xDFBEAD02 > -=-=-=-=- > This message is posted from an invalid address. Replying to it will > result in > undeliverable mail due to spam prevention. Sorry for the inconvenience. > > _______________________________________________ > Discuss mailing list > Discuss at blu.org > http://lists.blu.org/mailman/listinfo/discuss > -- Jerry Feldman <gaf at blu.org> Treasurer, Boston Linux and Unix http://www.blu.org
- References:
- [Discuss] Application config files
- From: gaf.linux at gmail.com (Jerry Feldman)
- [Discuss] Application config files
- From: dsr at randomstring.org (Dan Ritter)
- [Discuss] Application config files
- From: slitt at troubleshooters.com (Steve Litt)
- [Discuss] Application config files
- From: invalid at pizzashack.org (Derek Martin)
- [Discuss] Application config files
- Prev by Date: [Discuss] Application config files
- Next by Date: [Discuss] Application config files
- Previous by thread: [Discuss] Application config files
- Next by thread: [Discuss] Application config files
- Index(es):