On 12/6/2023 1:12 PM, MRAB via Python-list wrote:
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@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.

He's going to be writing his own calibration data files, though, so it should be safe for his purposes.

--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to