Re:Box – Python dictionary with dot notation
by kkirsche on Saturday December 18, 2021 @03:12PM
(#29608086)
If you don’t mind the heavier weight / newer version requirements, dataclasses from the standard lib also seem to solve this problem.
Re:Box – Python dictionary with dot notation
by whalesalad on Friday December 17, 2021 @10:16PM
(#29601246)
namedtuple is my usual goto for this but problem but I am glad to learn of SimpleNamespace
Re:Box – Python dictionary with dot notation
by youssefabdelm on Saturday December 18, 2021 @03:53AM
(#29602969)
Exactly my thought...I wonder how the Box library differs.
from types import SimpleNamespace
mydict = { "name": "moe", "age": 3, "test": {"name": "josh"} # wont work }
dotted = SimpleNamespace(*mydict)
print(dotted.name, dotted.age) # moe 3