Want to access a dict
via a String like dict[accessor]
while acccessor
is 'keyA.nestedKeyB'
. Found something here with Lambda and overwriting the dict
class ( https://stackoverflow.com/questions/39818669/dynamically-accessing-nested-dictionary-keys
) but unfortunetly there is no working example.
Code
data = { "keyA": { "nestedKeyB": "Hello" } }
print(data['keyA']['nestedKeyB']) # prints 'Hello'
accessor = 'keyA.nestedKeyB'
print(data[accessor]) # KeyError