[Python-Dev] Re: Improvement to SimpleNamespace

2020年4月15日 00:13:27 -0700

[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
_______________________________________________
Python-Dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/MNVWBEJI465QUODJEYPMAXPXOX3UDJ6Q/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to