Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: cl@isbd.net Newsgroups: comp.lang.python Subject: Re: Keepin constants, configuration values, etc. in Python - dedicated module or what? Date: Tue, 30 Sep 2014 18:50:04 +0100 Lines: 45 Message-ID: References: <54hqfb-nan.ln1@chris.zbmc.eu> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: individual.net zIxx3Edwj5CMnqeGxRKfvgN18HBOi/sEnQDDc0tIAm+mUGwT0= X-Orig-Path: not-for-mail Cancel-Lock: sha1:6lCyi7O+ihxz3gzyjhmL2nuAXBo= User-Agent: tin/2.2.0-20131224 ("Lochindaal") (UNIX) (Linux/3.13.0-36-generic (x86_64)) Xref: csiph.com comp.lang.python:78502 Neil D. Cerutti wrote: > 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 > That's OK except that it doesn't associate the different sections in any way, I need another level which includes these to indicate that these are values read from the ADC. There's another collection of config data for values read from the 1-wire bus. I guess I could have two config files, one for ADC and one for 1-wire. In fact I think that's the best approach so far. Ini format files are human readable (and more to the point editable), I can store them in the same directory as the database so they will get carried around with the data and the configparser module is built-in. -- Chris Green ยท