Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #95009
| Path | csiph.com!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <rosuav@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; 'computed': 0.07; 'subject:skip:c 10': 0.07; 'cc:addr:python-list': 0.09; 'conf': 0.09; 'url:github': 0.09; 'python': 0.10; 'wed,': 0.15; 'conditional': 0.16; 'fine;': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'great!': 0.16; 'head,': 0.16; 'keyword,': 0.16; 'pairs': 0.16; 'pulling': 0.16; 'url:py': 0.16; 'wrote:': 0.16; 'later': 0.16; 'string': 0.17; 'config': 0.18; 'duplicate': 0.18; 'settings.': 0.18; 'hack': 0.18; 'language': 0.19; 'versions': 0.20; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'aug': 0.20; 'otherwise,': 0.20; 'programming': 0.22; 'code,': 0.23; 'fit': 0.23; 'bit': 0.23; '(or': 0.23; 'seems': 0.23; 'this:': 0.23; 'header:In-Reply-To:1': 0.24; "doesn't": 0.26; 'example': 0.26; 'error': 0.27; 'checking': 0.27; 'message-id:@mail.gmail.com': 0.27; 'tend': 0.27; 'page.': 0.28; 'checking.': 0.29; 'them?': 0.29; 'whitespace': 0.29; 'anywhere': 0.30; 'code': 0.30; 'normally': 0.30; "i'd": 0.31; 'another': 0.32; "can't": 0.32; 'screen': 0.32; 'subject:) ': 0.32; 'maybe': 0.33; 'source': 0.33; "d'aprano": 0.33; 'quotes': 0.33; 'right?': 0.33; 'steven': 0.33; 'file': 0.34; 'add': 0.34; 'that,': 0.34; 'received:google.com': 0.35; 'so,': 0.35; 'files,': 0.35; 'requiring': 0.35; 'something': 0.35; 'level': 0.35; 'sometimes': 0.35; 'but': 0.36; 'there': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'really': 0.37; 'two': 0.37; 'files': 0.38; 'enough': 0.39; 'rather': 0.39; 'where': 0.40; 'some': 0.40; 'your': 0.60; 'more': 0.63; 'personal': 0.63; 'complete': 0.63; 'skip:$ 10': 0.67; 'apart': 0.70; 'carefully': 0.72; 'feeling': 0.72; 'power': 0.72; 'grow': 0.75; 'chrisa': 0.84; 'entry,': 0.84; 'url:config': 0.84; 'url:master': 0.84; 'warning.': 0.84; 'to:none': 0.91; 'drink': 0.93; 'hand,': 0.97 |
| 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:cc :content-type; bh=Bw1zjcOOa9mYzjrqYtVRuoFozFCxQrnzuIY7KYlmMjA=; b=lkn03KYgsxo9CV6SZfETU6W/il42DuwwVuu55C23DJ7zR7mTordd2S9BmTzf+KZqWO XbdROXLH4zBjOUoFWMe4qanGLeVn+JHhzp8vQ1+c7HdxBYGgvXVSFLsGZNZLEnxFvKIm dHlSmP+8yveZXbM2JKJX+CR9gmahtAkqo3QqoIip2copyuX4y4S59sy3caJK4TU1WnNt k7g6lFpfVjsew7ZoG4eDiaiijteTl/bMVBHaF2FVgfgKRs08sjcVJHWQz1tfq6CE+klg hfCBr0+7ASnbuDT20zCaiphEaB2AIuaAHmpytb+/KS4afABEBylS0uWjdreG5Hl1Sd0i /JJw== |
| MIME-Version | 1.0 |
| X-Received | by 10.107.12.141 with SMTP id 13mr8497997iom.157.1438768911549; Wed, 05 Aug 2015 03:01:51 -0700 (PDT) |
| In-Reply-To | <55c1ca1b$0$1582$c3e8da3$5496439d@news.astraweb.com> |
| References | <87k2teq9tb.fsf@Equus.decebal.nl> <663ad259-48e0-4eec-a946-7cd03805ddb1@googlegroups.com> <mailman.1216.1438718366.3674.python-list@python.org> <55c1ca1b$0$1582$c3e8da3$5496439d@news.astraweb.com> |
| Date | Wed, 5 Aug 2015 20:01:51 +1000 |
| Subject | Re: Most Pythonic way to store (small) configuration |
| From | Chris Angelico <rosuav@gmail.com> |
| Cc | "python-list@python.org" <python-list@python.org> |
| Content-Type | text/plain; charset=UTF-8 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.20+ |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://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 | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1237.1438768914.3674.python-list@python.org> (permalink) |
| Lines | 45 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1438768914 news.xs4all.nl 2847 [2001:888:2000:d::a6]:45959 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:95009 |
Show key headers only | View raw
On Wed, Aug 5, 2015 at 6:32 PM, Steven D'Aprano <steve+comp.lang.python@pearwood.info> wrote: > My own personal feeling is that using code as config is a little > disquieting. It's a bit of a code smell. Do you really need that much power > just to allow people to set some configuration settings? Using a Turing > Complete programming language just to set a bunch of name:value pairs seems > to be gross overkill. > > But on the other hand, config systems do tend to grow in power. People often > want conditional and computed settings. Rather than invent your own (buggy) > mini-language to allow conf like this: > > if $PLATFORM = 'Windows' set location = 'C:\The Stuff'; > if $PLATFORM = 'Linux' set location = $baselocation + '/thestuff'; > > using Python seems like a much better idea. I often have config files where the example is really simple, like this: https://github.com/Rosuav/LetMeKnow/blob/master/keys_sample.py https://github.com/Rosuav/Yosemite/blob/master/config.py but the in-production versions sometimes have a teensy bit more code in them - maybe an if-expression, maybe pulling something from os.environ. In both of those cases, any person editing the config file will also have full power to tamper with the source code, so the security issue doesn't apply; and apart from requiring quotes around string values, it's pretty much the level of simplicity you'd get out of any other config file format. You get comments, you get freedom to add whitespace anywhere you like (or not add it, if you so desire), it's great! Right? Well, there is another subtlety, and that's that there's no error checking. If you duplicate an entry, nobody will issue even a warning. For small config files, that's fine; but what if you're editing something the size of postgresql.conf? You can't keep it all on screen or in your head, and if you simply search the file for some keyword, would you notice that there are two of them? So, I'd recommend this if - and ONLY if - the files are normally going to be small enough to fit on a single page. Otherwise, consider carefully whether you'd later on want to add error checking like that, and consider how hard it would be to hack that in. Drink responsibly. ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Most Pythonic way to store (small) configuration Cecil Westerhof <Cecil@decebal.nl> - 2015-08-02 12:11 +0200
Re: Most Pythonic way to store (small) configuration Chris Angelico <rosuav@gmail.com> - 2015-08-02 20:49 +1000
Re: Most Pythonic way to store (small) configuration Ben Finney <ben+python@benfinney.id.au> - 2015-08-02 21:54 +1000
Re: Most Pythonic way to store (small) configuration Cecil Westerhof <Cecil@decebal.nl> - 2015-08-02 18:51 +0200
Re: Most Pythonic way to store (small) configuration Lele Gaifax <lele@metapensiero.it> - 2015-08-02 22:02 +0200
Re: Most Pythonic way to store (small) configuration Cameron Simpson <cs@zip.com.au> - 2015-08-03 08:49 +1000
Re: Most Pythonic way to store (small) configuration Ben Finney <ben+python@benfinney.id.au> - 2015-08-03 11:16 +1000
Re: Most Pythonic way to store (small) configuration Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-08-02 16:12 +0100
Re: Most Pythonic way to store (small) configuration Tim Chase <python.list@tim.thechases.com> - 2015-08-02 16:11 -0500
Re: Most Pythonic way to store (small) configuration Dan Sommers <dan@tombstonezero.net> - 2015-08-03 04:02 +0000
Re: Most Pythonic way to store (small) configuration Steven D'Aprano <steve@pearwood.info> - 2015-08-03 23:38 +1000
Re: Most Pythonic way to store (small) configuration Chris Angelico <rosuav@gmail.com> - 2015-08-03 23:46 +1000
Re: Most Pythonic way to store (small) configuration Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-08-03 15:37 +0100
Re: Most Pythonic way to store (small) configuration marco.nawijn@colosso.nl - 2015-08-04 07:53 -0700
Re: Most Pythonic way to store (small) configuration Irmen de Jong <irmen.NOSPAM@xs4all.nl> - 2015-08-04 19:06 +0200
Re: Most Pythonic way to store (small) configuration marco.nawijn@colosso.nl - 2015-08-04 11:37 -0700
Re: Most Pythonic way to store (small) configuration Ben Finney <ben+python@benfinney.id.au> - 2015-08-05 05:59 +1000
Re: Most Pythonic way to store (small) configuration Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-08-05 18:32 +1000
Re: Most Pythonic way to store (small) configuration Chris Angelico <rosuav@gmail.com> - 2015-08-05 20:01 +1000
Re: Most Pythonic way to store (small) configuration Michael Torrie <torriem@gmail.com> - 2015-08-04 19:32 -0600
Re: Most Pythonic way to store (small) configuration Grant Edwards <invalid@invalid.invalid> - 2015-08-05 14:00 +0000
Re: Most Pythonic way to store (small) configuration random832@fastmail.us - 2015-08-04 22:44 -0400
Re: Most Pythonic way to store (small) configuration Michael Torrie <torriem@gmail.com> - 2015-08-04 22:48 -0600
Re: Most Pythonic way to store (small) configuration Rustom Mody <rustompmody@gmail.com> - 2015-08-04 21:55 -0700
Re: Most Pythonic way to store (small) configuration Lele Gaifax <lele@metapensiero.it> - 2015-08-05 08:54 +0200
Re: Most Pythonic way to store (small) configuration Tim Chase <python.list@tim.thechases.com> - 2015-08-05 08:18 -0500
Re: Most Pythonic way to store (small) configuration Rustom Mody <rustompmody@gmail.com> - 2015-08-05 06:37 -0700
Re: Most Pythonic way to store (small) configuration Tim Chase <python.list@tim.thechases.com> - 2015-08-05 15:55 -0500
Re: Most Pythonic way to store (small) configuration Marko Rauhamaa <marko@pacujo.net> - 2015-08-06 00:47 +0300
Re: Most Pythonic way to store (small) configuration Tim Chase <python.list@tim.thechases.com> - 2015-08-05 18:43 -0500
Re: Most Pythonic way to store (small) configuration Chris Angelico <rosuav@gmail.com> - 2015-08-06 10:07 +1000
Re: Most Pythonic way to store (small) configuration Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-08-06 17:33 +1000
Re: Most Pythonic way to store (small) configuration Chris Angelico <rosuav@gmail.com> - 2015-08-06 17:51 +1000
Re: Most Pythonic way to store (small) configuration Rustom Mody <rustompmody@gmail.com> - 2015-08-05 18:01 -0700
Re: Most Pythonic way to store (small) configuration Rustom Mody <rustompmody@gmail.com> - 2015-08-05 18:06 -0700
Re: Most Pythonic way to store (small) configuration Rustom Mody <rustompmody@gmail.com> - 2015-08-05 06:46 -0700
Re: Most Pythonic way to store (small) configuration Steven D'Aprano <steve@pearwood.info> - 2015-08-06 00:08 +1000
Re: Most Pythonic way to store (small) configuration Rustom Mody <rustompmody@gmail.com> - 2015-08-05 07:25 -0700
csiph-web