How/where to store calibration values - written by program A, read by program B
MRAB
python at mrabarnett.plus.com
Wed Dec 6 13:12:20 EST 2023
On 2023-12-06 12:23, Thomas Passin via Python-list wrote:
> On 12/6/2023 6:35 AM, Barry Scott via Python-list wrote:
>>
>>
>>> On 6 Dec 2023, at 09:32, Chris Green via Python-list <python-list at python.org> wrote:
>>>
>>> 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.
>>
>> JSON will allow you to nest dictionaries.
>>
>> {
>> 'KEY1': {
>> 'a': v1
>> 'c': v3
>> 'd': v4
>> }
>> 'KEY2': {
>> 'a': v7
>> 'b': v5
>> 'd': v6
>> }
>> }
>>
>> Personally I would not use .ini style these days as the format does not include type of the data.
>
> Neither does JSON. Besides, JSON is more complicated than necessary
> here - in fact, your example isn't even legal JSON since lines are
> missing commas.
>
> Fun fact - for at least some, maybe most, JSON files, using eval() on
> them is hugely faster than using Python's standard JSON library. I
> learned this when I wanted to ingest a large browser bookmarks JSON
> file. It wouldn't matter for a much smaller file, of course.
>
It would be safer if you used literal_eval.
More information about the Python-list
mailing list