TypeError: list indices must be integers, not dict

  • you can try this, it works for me
dataArray=data['execution']
for i in range(len(dataArray)):
    cmd = dataArray[i]['test_case']['scriptname']
  • This exactly loops by indices, so there will not be any confusion,
  • For me this is very simple and understandable

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']

Tags:

Python