Re: Improvement to SimpleNamespace
15 Apr
2020
15 Apr
'20
3:06 a.m.
[Serhiy]
As a workaround you can use
object_hook=lambda x: SimpleNamespace(**x)
That doesn't suffice because some valid JSON keys are not valid identifiers. You still need a way to get past those when they arise: catalog.books.fiction['Paradise Lost'].isbn Also, it still leaves you with using setattr(ns, attrname, attrvalue) or tricks with vars() when doing updates. The AttrDict recipe is popular for a reason. Raymond
1434
Age (days ago)
1434
Last active (days ago)
2 comments
3 participants
participants (3)
-
Eric Snow
-
Raymond Hettinger
-
Serhiy Storchaka