How to loop through containers in script module

I have a script module that builds an SQL query based on “isPropertyDefined” that works ok but I want to loop the script x amount of times each time checking a different container. What I cannot solve is how to change from one container to the next. The script has the following:

cont = event.source.parent.getComponent(“1”)
This works ok but I want to change this on each loop to:

cont = event.source.parent.getComponent(“1”)
cont = event.source.parent.getComponent(“2”)
cont = event.source.parent.getComponent(“3”) …etc

If I put in:

i +=1
cont = event.source.parent.getComponent(i)

it fails as does:

i +=1
j = “”" + str(i)+"""
cont = event.source.parent.getComponent(j)

What am I doing wrong???

You just need to do the following:i +=1 cont = event.source.parent.getComponent(str(i))