I agree, I don't like the magic string approach (even if it is mostly just dot-notation attribute lookup). However, there is some good stuff here, and nested data lookup when value existence is unknown is a pain point for me.
In addition to the string based lookup, it looks like there is an attempt at a pythonic approach:
from glom import T
spec = T['system']['planets'][-1].values()
glom(target, spec)
# ['jupiter', 69]
For me though, while I can understand what is going on, it doesn't feel pythonic.
Here's what I would love to see:
from glom import nested
nested(target)['system']['planets'][-1].values()
And I would love (perhaps debatably) for that to be effectively equivalent to:
nested(target).system.planets[-1].values()
Possible?
---
edit: Ignore the above idea. I thought about this a bit more and the issue that your T object solves is that in my version:
nested(target)['system']
the result is ambiguous. Is this the end of the path query and should return original non-defaulting dict, or the middle of the path query and should return a defaulting dict? Unknown.
The T object is a good solution for this.
In addition to the string based lookup, it looks like there is an attempt at a pythonic approach:
For me though, while I can understand what is going on, it doesn't feel pythonic.Here's what I would love to see:
And I would love (perhaps debatably) for that to be effectively equivalent to: Possible?--- edit: Ignore the above idea. I thought about this a bit more and the issue that your T object solves is that in my version:
the result is ambiguous. Is this the end of the path query and should return original non-defaulting dict, or the middle of the path query and should return a defaulting dict? Unknown.The T object is a good solution for this.