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

Neil D. Cerutti neilc at
Tue Sep 30 18:16:47 CEST 2014

On 9/30/2014 7:35 AM, cl at 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.

Description=Leisure Battery Voltage

Description=Starter Battery Voltage

Description=Leisure Battery Current

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

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

Neil Cerutti

More information about the Python-list mailing list