I am using the glom package to help with traversing a big dictionary.
Given this data:
data = {
'groups': [
{'instance': {'name': 'football'}},
{'instance': {'name': 'rugby'}},
{'id': 145, 'type': 'unknown'},
]
}
And using glom, I attempt to get the instance names:
import glom
instance_names = glom(data, ('groups', ['instance.name']))
I receive an Error:
glom.core.PathAccessError: could not access 'instance', part 0 of Path('instance', 'name'), got error: KeyError('instance')
How can I skip the objects where the instance
key does not exist?
Update
I have tried to skip the exception but then I receive empty results:
instance_names = glom(data, ('groups', ['instance.name']), skip_exc=PathAccessError)