-1

I am trying to perform a loop over a set of columns as below:

for i in range(len(parent)):
    for j in range(4):
        table.cell(i, j).text = str(locals()["child_" + i + "_" + j])

I am getting an error

TypeError: can only concatenate str (not "int") to str

Error in line table.cell(i, j).text = str(locals()["child_" + i + "_" + j])

dark horse
  • 447
  • 1
  • 6
  • 17
  • 1
    Convert the `int` to `str` before concatenating: `table.cell(i, j).text = str(locals()["child_" + str(i) + "_" + str(j)])` – DirtyBit Feb 11 '19 at 09:27

1 Answers1

5
["child_" + i + "_" + j]

should be

["child_" + str(i) + "_" + str(j)]

Convert int to str before concatenating.

Jay
  • 24,173
  • 25
  • 93
  • 141