News for hackers. Stuff that matters.
Re:Box: Python dictionaries with recursive dot notation access by Karunamon on Friday May 05, 2017 @01:34PM (#14275225)
So then what are you supposed to deserialize nested data structures like JSON into? Dictionaries are the obvious "right" way, Python's annoying tooling aside.
Re:Box: Python dictionaries with recursive dot notation access by sevensor on Friday May 05, 2017 @04:51PM (#14276747)
I'd say that dictionaries are only the obvious "right" way if you're not planning on accessing any of their fields. Otherwise you have some set of expected fields, in which case you can define a namedtuple and avoid a vast array of nasty surprises. It's really easy to initialize a namedtuple from a dict (use ), as long as the dict has the right fields. If it doesn't, and you're planning on using its fields, the fact that this raises an exception is a good thing.
Re:Box: Python dictionaries with recursive dot notation access by msellout on Friday May 05, 2017 @07:23PM (#14277564)
What do you think of this library: https://github.com/selik/destructure

It'll enforce schema and destructure the nested dict/list that results from JSON decoding.

Re:Box: Python dictionaries with recursive dot notation access by xapata on Friday May 05, 2017 @07:28PM (#14277594)
That's like asking, "What data structure should I use for this CSV file?"

Depends on the usage. Sometimes you leave them as nested dictionaries and lists. Sometimes you transform them into tabular data. Sometimes you aggregate, etc.

Re:Box: Python dictionaries with recursive dot notation access by IanCal on Friday May 05, 2017 @01:52PM (#14275382)
Namedtuples or classes that represent the data, I'd suggest personally.
Re:Box: Python dictionaries with recursive dot notation access by pdonis on Friday May 05, 2017 @02:40PM (#14275780)
I would agree. Namedtuple has an asdict method so that reserialization to JSON is simple; you can do the same for a class.