For changing the values from 10 to 18, 19 or 20, I am splitting the string, access the substrings and then trying to change it. Its working but just not changing the values. Here is the solution I am trying to implement:

```
oldFileName = 'tryout.hmo'
newFileName = 'tryout_NEW.hmo'
topoFileName = 'Density.topo'

readme = open( oldFileName, "r" )
oldLines = readme.readlines()       

readme = open(topoFileName, "r")
Lines = readme.readlines()
readme.close()

newFile = open(newFileName,"w")

for row in oldLines:
    for line in Lines:
        tmp = line.split()
    list =  row.rstrip()
    tmp1 = list.split()
    newFile.write(row)
    if row.find("BEG_ELEM_DATA") > -1:
       if tmp[0] == tmp1[0]:
           if tmp[2] == 1 and tmp[3] == 0:
            # it is magnet, value 18
             newFile.write(tmp1.replace(tmp1[1], "18"))

           elif tmp[2] == 1 and tmp[3] == 1:               
              # it is iron, value 19
             newFile.write(tmp1.replace(tmp1[1], "19"))

           else:
            # it is air, value 20
             newFile.write(tmp1.replace(tmp1[1], "20")) 

newFile.close()      

```

I would really appreciate it if you could able to solve this problem in above script, then I guess it should work.