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


Groups > comp.lang.python > #78492

Re: Keepin constants, configuration values, etc. in Python - dedicated module or what?

Path csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'syntax': 0.04; 'subject:Python': 0.06; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'spelling': 0.09; 'subject:module': 0.09; 'subject:skip:c 10': 0.09; '(apologies': 0.16; '(it': 0.16; '7:35': 0.16; 'definitions,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject: \n ': 0.16; 'subject:etc.': 0.16; 'subject:values': 0.16; 'wrote:': 0.18; 'seems': 0.21; 'header:User-Agent:1': 0.23; 'alternate': 0.24; 'convenient': 0.24; 'necessary.': 0.24; 'looks': 0.24; "i've": 0.25; 'values': 0.27; 'header:X-Complaints-To:1': 0.27; 'header :In-Reply-To:1': 0.27; 'fixed': 0.29; 'am,': 0.29; 'thus': 0.29; 'subject:what': 0.31; 'file': 0.32; 'lists': 0.32; "i'd": 0.34; 'something': 0.35; 'but': 0.35; 'like,': 0.36; 'shows': 0.36; 'subject:?': 0.36; 'skip:[ 10': 0.38; 'whatever': 0.38; 'to:addr :python-list': 0.38; 'files': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'even': 0.60; 'read': 0.60; 'simple': 0.61; 'field': 0.63; 'subject:. ': 0.67; 'verification': 0.83; 'battery': 0.84; 'configparser': 0.84; 'voltage': 0.84; 'numerous': 0.93
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From "Neil D. Cerutti" <neilc@norwich.edu>
Subject Re: Keepin constants, configuration values, etc. in Python - dedicated module or what?
Date Tue, 30 Sep 2014 12:16:47 -0400
References <54hqfb-nan.ln1@chris.zbmc.eu>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host jackman.norwich.edu
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0
In-Reply-To <54hqfb-nan.ln1@chris.zbmc.eu>
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 <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.14488.1412093823.18130.python-list@python.org> (permalink)
Lines 45
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1412093823 news.xs4all.nl 2859 [2001:888:2000:d::a6]:55862
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:78492

Show key headers only | View raw


On 9/30/2014 7:35 AM, cl@isbd.net wrote:
> Thus I'd have something like (apologies for any syntax errors):-
>
> cfg = { "LeisureVolts": ["AIN0", 0.061256, "Leisure Battery Voltage"],
>          "StarterVolts": ["AIN1", 0.060943, "Starter Battery Voltage"],
>          "LeisureAmps1": ["AIN2", 0.423122, "Leisure Battery Current"}
>
> (It might be better to makes those lists dictionaries, but it shows
> the idea)

Using configparser.ConfigParser to read an ini-format seems like a good 
idea. I use it for my own numerous fixed format data file definitions, 
and it's been convenient and even extensible.

[LeisureVolts]
Description=Leisure Battery Voltage
Code=AIN0
Value=0.061256

[StarterVolts]
Description=Starter Battery Voltage
Code=AIN1
Value=0.060943

[LeisureAmps1]
Description=Leisure Battery Current
Code=AIN2
Value=0.423122

I've set it up so I can understand abbreviations for the field names, 
for when I want to be lazy.

Some of my values are dictionaries, which looks like this in my files 
(an alternate spelling of one of the above entries):

LeisureVolts=desc:Leisure Battery Voltage
              code:AIN2
             value:0.061256

It's simple to hook into ConfigParser to get whatever meaning you'd 
like, and whatever verification you'd find necessary.

-- 
Neil Cerutti

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


Thread

Keepin constants, configuration values, etc. in Python - dedicated module or what? cl@isbd.net - 2014-09-30 12:35 +0100
  Re:Keepin constants, configuration values, etc. in Python - dedicated module or what? Dave Angel <davea@davea.name> - 2014-09-30 09:14 -0400
    Re: Re:Keepin constants, configuration values, etc. in Python - dedicated module or what? cl@isbd.net - 2014-09-30 15:55 +0100
      Re: Keepin constants, configuration values, etc. in Python - dedicated module or what? Dave Angel <d@davea.name> - 2014-10-02 14:50 -0400
  Re: Keepin constants, configuration values, etc. in Python - dedicated module or what? Rustom Mody <rustompmody@gmail.com> - 2014-09-30 06:15 -0700
    Re: Keepin constants, configuration values, etc. in Python - dedicated module or what? cl@isbd.net - 2014-09-30 16:06 +0100
      Re: Keepin constants, configuration values, etc. in Python - dedicated module or what? jkn <jkn_gg@nicorp.f9.co.uk> - 2014-09-30 08:59 -0700
      Re: Keepin constants, configuration values, etc. in Python - dedicated module or what? Rustom Mody <rustompmody@gmail.com> - 2014-09-30 09:39 -0700
        Re: Keepin constants, configuration values, etc. in Python - dedicated module or what? Chris Angelico <rosuav@gmail.com> - 2014-10-01 02:51 +1000
          Re: Keepin constants, configuration values, etc. in Python - dedicated module or what? Rustom Mody <rustompmody@gmail.com> - 2014-09-30 10:01 -0700
            Re: Keepin constants, configuration values, etc. in Python - dedicated module or what? Chris Angelico <rosuav@gmail.com> - 2014-10-01 03:15 +1000
              Re: Keepin constants, configuration values, etc. in Python - dedicated module or what? Rustom Mody <rustompmody@gmail.com> - 2014-09-30 10:31 -0700
                Re: Keepin constants, configuration values, etc. in Python - dedicated module or what? Chris Angelico <rosuav@gmail.com> - 2014-10-01 03:46 +1000
              Re: Keepin constants, configuration values, etc. in Python - dedicated module or what? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-10-02 00:49 +1000
                Re: Keepin constants, configuration values, etc. in Python - dedicated module or what? Chris Angelico <rosuav@gmail.com> - 2014-10-02 00:55 +1000
            Re: Keepin constants, configuration values, etc. in Python - dedicated module or what? cl@isbd.net - 2014-09-30 18:30 +0100
              Re: Keepin constants, configuration values, etc. in Python - dedicated module or what? Chris Angelico <rosuav@gmail.com> - 2014-10-01 03:49 +1000
        Re: Keepin constants, configuration values, etc. in Python - dedicated module or what? Rustom Mody <rustompmody@gmail.com> - 2014-10-16 18:24 -0700
  Re: Keepin constants, configuration values, etc. in Python - dedicated module or what? "Neil D. Cerutti" <neilc@norwich.edu> - 2014-09-30 12:16 -0400
    Re: Keepin constants, configuration values, etc. in Python - dedicated module or what? cl@isbd.net - 2014-09-30 18:50 +0100

csiph-web