How/where to store calibration values - written by program A, read by program B

Chris Green cl at isbd.net
Wed Dec 6 04:32:02 EST 2023


Thomas Passin <list1 at tompassin.net> wrote:
> On 12/5/2023 11:50 AM, MRAB via Python-list wrote:
> > On 2023-12-05 14:37, Chris Green via Python-list wrote:
> >> Is there a neat, pythonic way to store values which are 'sometimes'
> >> changed?
> >>
> >> My particular case at the moment is calibration values for ADC inputs
> >> which are set by running a calibration program and used by lots of
> >> programs which display the values or do calculations with them.
> >>
> >>  From the program readability point of view it would be good to have a
> >> Python module with the values in it but using a Python program to
> >> write/update a Python module sounds a bit odd somehow.
> >>
> >> I could simply write the values to a file (or a database) and I
> >> suspect that this may be the best answer but it does make retrieving
> >> the values different from getting all other (nearly) constant values.
> >>
> >> Are there any Python modules aimed specifically at this sort of
> >> requirement?
> >>
> > Some kind of key/value store sounds like the correct solution. I 
> > wouldn't go as far a database - that's overkill for a few calibration 
> > values.
> > 
> > I might suggest TOML, except that Python's tomllib (Python 3.11+) is 
> > read-only!
> > 
> > Personally, I'd go for lines of:
> > 
> >      key1: value1
> >      key2: value2
> > 
> > Simple to read, simple to write.
> 
> Just go with an .ini file. Simple, well-supported by the standard 
> library. And it gives you key/value pairs.
> 
My requirement is *slightly* more complex than just key value pairs,
it has one level of hierarchy, e.g.:-

    KEY1:
      a: v1
      c: v3
      d: v4
    KEY2:
      a: v7
      b: v5
      d: v6

Different numbers of value pairs under each KEY.

-- 
Chris Green
·


More information about the Python-list mailing list