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


Groups > comp.lang.python > #95075

Re: Most Pythonic way to store (small) configuration

Path csiph.com!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed8.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.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'anyway.': 0.04; 'string.': 0.04; 'escape': 0.07; 'subject:skip:c 10': 0.07; 'trailing': 0.07; 'cc:addr:python-list': 0.09; 'backwards': 0.09; 'marking': 0.09; 'oh,': 0.09; 'yeah,': 0.09; 'thu,': 0.15; 'complexity,': 0.16; 'configuring': 0.16; 'dsl,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'sequence:': 0.16; 'shot.': 0.16; 'string:': 0.16; 'unquoted': 0.16; 'wrote:': 0.16; 'string': 0.17; 'say,': 0.18; 'input': 0.18; '>>>': 0.20; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'aug': 0.20; 'ascii': 0.22; 'parsing': 0.22; 'strip': 0.22; 'trying': 0.22; 'am,': 0.23; 'this:': 0.23; 'second': 0.24; 'tim': 0.24; 'header:In-Reply- To:1': 0.24; 'sort': 0.25; "i've": 0.25; "doesn't": 0.26; 'chris': 0.26; 'error': 0.27; 'separate': 0.27; 'least': 0.27; 'message- id:@mail.gmail.com': 0.27; 'sequence': 0.27; 'function': 0.28; 'fine': 0.28; 'about.': 0.29; 'be:': 0.29; 'cases.': 0.29; 'chase': 0.29; 'end,': 0.29; 'idea,': 0.29; 'spaces': 0.29; 'strings,': 0.29; 'whitespace': 0.29; "i'm": 0.30; 'putting': 0.30; 'writes': 0.30; 'option': 0.31; 'anyone': 0.32; 'embedded': 0.32; 'subject:) ': 0.32; 'though,': 0.32; 'maybe': 0.33; 'usually': 0.33; "d'aprano": 0.33; 'point,': 0.33; 'quotes': 0.33; 'steven': 0.33; 'values.': 0.33; 'file': 0.34; 'add': 0.34; 'server': 0.34; 'requirements': 0.35; 'received:google.com': 0.35; 'instance': 0.35; 'unicode': 0.35; 'something': 0.35; "isn't": 0.35; 'sometimes': 0.35; 'but': 0.36; 'project': 0.36; 'there': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'two': 0.37; 'being': 0.37; 'display': 0.37; 'setting': 0.37; 'one,': 0.37; 'wanted': 0.37; 'starting': 0.37; 'itself': 0.38; 'someone': 0.38; 'end': 0.39; 'sure': 0.39; 'whatever': 0.39; 'does': 0.39; 'where': 0.40; 'still': 0.40; 'space': 0.40; 'some': 0.40; 'care': 0.60; 'your': 0.60; 'leading': 0.61; 'provide': 0.61; 'places': 0.64; "they're": 0.66; 'thursday': 0.66; 'nations': 0.72; 'august': 0.75; 'prompt': 0.79; '127.0.0.1': 0.84; 'chrisa': 0.84; 'complexity': 0.84; 'escapes,': 0.84; 'revolution,': 0.84; 'touching': 0.84; 'to:none': 0.91
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=ATn4Ast5sye1fEmE0wRKPxDhu/67/LnnTwWcPed4RXM=; b=u2YEB6VRWctT6cUIAqxWELLf/ApbXZ6hD2t/YG+KjcoPhSdv2lOblzx0VomIki/ntA o4kfMyrpAwfz8VvlOxJR8KZ00JJKDHp+/BI/tPMpcfp/8WjpR2+ATX/IHaN8CcMn7Scc tGPmwL6b6NkwN+jLusAa8B1mdCV9vhNyA0HrxmNWjsSYLn81/2KECe+xT901fKU1J0YP CwGNgGQy/BfsxVgwbCDw+Clf8jTaH6Kx8kHNgfuWBWldDB1lqusgd238M7KUME6srZv7 FQBPnZmaCa/wtIBT44Bqo2wOXWsj70jumM52jmDB+b5a4+DSSRD2tbtpwKcpCVOo1ey2 zxyg==
MIME-Version 1.0
X-Received by 10.107.12.141 with SMTP id 13mr269757iom.157.1438847467289; Thu, 06 Aug 2015 00:51:07 -0700 (PDT)
In-Reply-To <55c30dd9$0$1653$c3e8da3$5496439d@news.astraweb.com>
References <87k2teq9tb.fsf@Equus.decebal.nl> <mailman.1240.1438781266.3674.python-list@python.org> <36333f24-3bda-4534-b22f-20c99e8d791c@googlegroups.com> <mailman.1247.1438808479.3674.python-list@python.org> <87fv3xpfuu.fsf@elektro.pacujo.net> <20150805184354.596616fd@bigbox.christie.dr> <mailman.1251.1438819658.3674.python-list@python.org> <55c30dd9$0$1653$c3e8da3$5496439d@news.astraweb.com>
Date Thu, 6 Aug 2015 17:51:07 +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.1271.1438847469.3674.python-list@python.org> (permalink)
Lines 88
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1438847469 news.xs4all.nl 2849 [2001:888:2000:d::a6]:54359
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:95075

Show key headers only | View raw


On Thu, Aug 6, 2015 at 5:33 PM, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> wrote:
> On Thursday 06 August 2015 10:07, Chris Angelico wrote:
>
>> On Thu, Aug 6, 2015 at 9:43 AM, Tim Chase <python.list@tim.thechases.com>
>> wrote:
>>> Significant whitespace?  Not usually simple (just stuck touching a
>>> project where someone committed with tons of trailing whitespaces.
>>> grumble), so strip 'em off as if they're an error condition.  I've
>>> never had a config-file where I wanted leading/trailing whitespace as
>>> significant.
>>
>> If you're configuring a prompt, sometimes you need to be able to
>> include a space at the end of it.
>
> "Sometimes"? What sort of filthy perv doesn't separate their prompts from
> the user input with at least one space? Disgusting, I call it.
>
>     this is a prompt and this isn't
>
> versus
>
>     this is a promptand this isn't
>
> Come the revolution, anyone who writes the second will be taken out and
> shot.

Oh, well, there are these people in backwards nations that still have
prompts that look like this:

C:\>

and have no space after them. I *was* trying to be courteous, but
maybe courtesy is wasted on those who'll be shot come the revolution
anyway.

> The right solution to that is to have the display function add a space to
> the end of the prompt if there isn't already one, that way you don't need to
> care about putting a space at the end of the prompt yourself.

That's an option that solves one specific instance of the problem, but
I'm sure there are other places where you may or may not want a
trailing space, so it needs a marker.

>> Since trailing whitespace on a line
>> in the file itself is a bad idea, you need some way of marking it.
>
> I'm partial to one of two schemes:
>
> - strings need to be quoted, so leading and trailing spaces are easy:
>
>   key = " this has both leading and trailing spaces "

Yeah, this is fine for a lot of cases. It does add small complexity,
though, to the simple case where you're setting simple tokens as
values.

> - strings don't need to be quoted, and spaces are significant *except*
>   at  the ends of the string:
>
>   key = this has no leading or trailing spaces
>
>   If you need spaces at the end, use an escape sequence:
>
>   key = \sthis has both leading and trailing spaces\s
>
> say, or ^SP or \N{SPACE} or whatever floats your boat. Unless your
> requirements are limited to only printable ASCII strings, you're going to
> need to provide some sort of escape sequence anyway, to allow (say)
> newlines.

This is starting to get toward a full-blown DSL, which is costly. At
this point, you may as well go for something well-known, which is what
this thread's all about.

A compromise might be: Unquoted strings get trimmed and are restricted
to one line, but if you want leading/trailing spaces, or
leading/trailing quote characters, or embedded newlines, or Unicode
escapes, you must first put quotes around the string.

server = 127.0.0.1
message = "Hi there!\nTwo line message being delivered."
windows_path = c:\users\adam

That way, you pay the complexity cost of full string parsing only if
you actually need it.

ChrisA

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


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