Python update variable name in for loop

Hello all,
Not sure if this question has been answered already.

I have some xml Element variable as below:

child19 = core_elem_dcache.find('stat[@name="read_accesses"]')
    child20 = core_elem_dcache.find('stat[@name="write_accesses"]')
    child21 = core_elem_dcache.find('stat[@name="read_misses"]')
    child22 = core_elem_dcache.find('stat[@name="write_misses"]'

Next I want to change the values of these corresponding elements like below:

child20.set('value', str(params[19]))
child21.set('value', str(params[20]))
child22.set('value', str(params[21])) ######params is a list already read before from a text file

Now instead of setting setting the values manually for each element, I wanted to do a for loop for a range (10,100). But I am not sure how to update the "child" element dynamically.

I tried following:

for x in range(13,23):
        child{x}.set('value',str(params[x-1]))

which surely gave me error:

File "abc.py", line 99
    child{x}.set('value',str(params[x-1]))
         ^
SyntaxError: invalid syntax

Kindly help.

Check your python documentation for the 'exec' function. if you can't use child[index] and have to use hard names, exec is your friend for creating on the fly code (normally you would not do this though.. but there are some cases...).

Instead of using sequentially named variables, why not use a list (if you don't need to start with 19), or a dict?

child = {}
child[19] = 'value 19'
child[20] = 'value 20'

for x in range(19,20):
    child[x] = 'another value ' + str(x)