Earlier quoted context omitted.
Can dataclasses be serialized just as easily?
Yes via pickle. Or for JSON, dataclasses_json
DotDict: A simple Python library to make chained attributes possible
41–50 of 55 posts
Re: DotDict: A simple Python library to make chained attributes possible
#42Earlier quoted context omitted.
Yes via pickle. Or for JSON, dataclasses_json
Be aware that pickle is unsafe (as documented near the top of https://docs.python.org/3/library/pickle.html ), so prefer other serialization formats except between trusted processes
If I want all the python-specific nuance on disk, I know I'm in a bad place!
Re: DotDict: A simple Python library to make chained attributes possible
#43Earlier quoted context omitted.
My favorite example of this: https://old.reddit.com/r/learnprogramming/comments/kegalv/my...
That is a work of art, and also you have to appreciate the author’s commitment to the bit.
Re: DotDict: A simple Python library to make chained attributes possible
#44Earlier quoted context omitted.
Neither of these appear to have the chained attribute feature, from my surface level parse.
It's there on the readme/pypi home for both; unless i'm misunderstanding what you mean by "chained" from box import Box movie_box = Box({ "Robin Hood: Men in Tights": { "imdb stars": 6.7, "length": 104 } }) movie_box.Robin_Hood_Men_in_Tights.imdb_stars from munch import Munch b = Munch() b.hello = 'world' b.foo = Munch(lol=True) b.foo.lol
b.foo.lol = TrueRe: DotDict: A simple Python library to make chained attributes possible
#45Re: DotDict: A simple Python library to make chained attributes possible
#46Good video on this subject: https://www.youtube.com/watch?v=nDd2WVb_Enw
For anyone who doesn’t watch… the point being made is that this has been done so many times that yet another implementation was pulled from the stdlib in 3.12 (AttrDict).
It’s true. I’ve implemented this several times myself, and thought it was a new/good idea every time until I remembered how many abstractions it breaks if I use it anywhere.
I can’t promise I won’t do it again in a few weeks! `NaturalDictLite` is probably coming around in the accompanying rotation of bad name ideas :p
Re: DotDict: A simple Python library to make chained attributes possible
#47At least with Pydantic, there's the discipline to define the model and validation that a model instance is probably correct.
Re: DotDict: A simple Python library to make chained attributes possible
#48My general rule is, if I have a dict with a fixed set of keys, it should be a dataclass. Problem solved! Then if I need to send or receive it, it's an easy conversion to a Pydantic BaseModel.
Can dataclasses be serialized just as easily?
Re: DotDict: A simple Python library to make chained attributes possible
#49My general rule is, if I have a dict with a fixed set of keys, it should be a dataclass. Problem solved! Then if I need to send or receive it, it's an easy conversion to a Pydantic BaseModel.
Re: DotDict: A simple Python library to make chained attributes possible
#50My general rule is, if I have a dict with a fixed set of keys, it should be a dataclass. Problem solved! Then if I need to send or receive it, it's an easy conversion to a Pydantic BaseModel.
Can dataclasses be serialized just as easily?