Python use string variable as index/key for nested list/dict
Advertisements data = {‘virtualInterfaces’: [{"interfaceName": "abc", "interfaceState": "online"}, {"interfaceName": "axc", "interfaceState": "online"}, {"interfaceName": "xpto", "interfaceState": "offline"}]} foo = "[‘virtualInterfaces’][2][‘interfaceState’]" I need to use the var "foo" to get a specific value from data e.g data[foo] #should return "offline" I tried to use eval value = eval(data + foo) But didn´t work. Foo can have any… Read More Python use string variable as index/key for nested list/dict