TypeError: list indices must be integers, not dict

后端 未结 1 738
春和景丽
春和景丽 2020-12-09 16:29

My json file look likes this and I\'m trying to access the element syslog in a for loop.

{
  \"cleanup\":{
    \"folderpath\":\"/home/FBML7HR/lo         


        
相关标签:
1条回答
  • 2020-12-09 17:13

    You are looping over the values in the list referenced by data['execution'], not indices.

    Just use those values (dictionaries) directly:

    for i in data['execution']:
        cmd = i['test_case']['scriptname']
    

    You probably want to give that a more meaningful loop name:

    for entry in data['execution']:
        cmd = entry['test_case']['scriptname']
    
    0 讨论(0)
提交回复
热议问题