How/where to store calibration values - written by program A, read by program B
DL Neil
PythonList at DancesWithMice.info
Tue Dec 5 15:54:38 EST 2023
On 12/6/23 03: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?
Another programming-term for these might be "environment variables".
However, be aware that such also has a specific meaning at the Operating
System level.
1 Sysops Environment Variables exist completely outside the code. Python
interrogates the Sysops to fetch/set them. Can be problematic because
only apply on single machine and are not part of change-control, VS, etc.
2 A .con file (in my tradition, likely still .uni type in MSFT) or
similar, which contains the key:value pairs recommended elsewhere. There
are formal .con and .uni (etc) formats. Most of the teams I've
worked-with recently seem to settle on .JSON files which are
very-conveniently structured as (read into/written from) a Python
dictionary, and a single function-call interaction.
Word of warning/voice of [bitter] experience: ALWAYS *trumpet* any
changes in these values AND output them (as you would any "assumptions"
for a calculation) at the top of output reports. The trouble is that
humans assume continuity but such an arrangement is NOT idempotent -
which leads to complaints: "I ran it on Monday and got these results,
but when I ran it again on Tuesday, the results changed"...
Yes there are Python libraries. Choose your method/format first, and
then search - either Duckboards or straight from Pepi.
I have systems which use an DBMS for environment variables, but (a) only
when there's a significant number, and (b) when the application is
already connecting to the DBMS for processing [and maybe (c) because I
know my way around such tools so they're 'easy']. Not recommended!
--
Regards =dn
More information about the Python-list
mailing list