On Wed, Apr 15, 2020 at 2:09 PM Raymond Hettinger
<[email protected]> wrote:
>
> [GvR]
> > We should not try to import JavaScript's object model into Python.
>
> Yes, I get that. Just want to point-out that working with heavily nested
> dictionaries (typical for JSON) is no fun with square brackets and quotation
> marks.
>
My solution to that has usually been something along the lines of:
def get(obj, path):
for step in path.split("-"):
obj = obj[step]
return obj
print(get(catalog, 'clothing-mens-shoes-extra_wide-quantity'))
Will often be custom-tweaked to the situation, but the basic idea is the same.
ChrisA
_______________________________________________
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/XNCNGO3PYOTFVWKTYCO6T57JW3YH24D4/
Code of Conduct: http://python.org/psf/codeofconduct/