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: invalid at pizzashack.org (Derek Martin)
- Date: Fri, 12 Jul 2019 16:16:15 -0500
- In-reply-to: <20190712140720.38215f7c@mydesk.domain.cxm>
- References: <CAEvgogF9s200fVh_HaO2dHnmVV94vJ4gSSaWWOCj+YwN1mFMGw@mail.gmail.com> <20190712174001.zf5gvwbpfsqlkqjh@randomstring.org> <20190712140720.38215f7c@mydesk.domain.cxm>
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.
- Follow-Ups:
- [Discuss] Application config files
- From: slitt at troubleshooters.com (Steve Litt)
- [Discuss] Application config files
- From: richard.pieri at gmail.com (Rich Pieri)
- [Discuss] Application config files
- From: gaf at gapps.blu.org (Jerry Feldman)
- [Discuss] Application config files
- 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
- 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):