I've the following line in my file test.sdl:
PHASE 1: [Walk_Towards] [-, 1 to 3, -3 to -5][Ego:-4 to -2, FSL]
I want to replace the 1 to 3
with new random numbers (x,y) like 4 to 11
. This two numbers are not fixed and generated by a random method and changing for every iteration.
Note the 1 to 3 also not fixed and it is varied for every file
all the files have the same structure Like
PHASE 1: [] [, to , to ][Ego: to , FSL]
So I would like to change only the numbers in between the first 'to
'
My ultimate goal is to do an iteration lets say of 6. For every iterate the numbers will change
for example :
The current line is : PHASE 1: [Walk_Towards] [-, 1 to 3, -3 to -5][Ego:-4 to -2, FSL]
Second iteration will be based on a pre-defined variables (x,y) that changes every time randomly. So the result will be
`PHASE 1: [Walk_Towards] [-, x2 to y3, -3 to -5][Ego:-4 to -2, FSL]`
Third : PHASE 1: [Walk_Towards] [-, x2 to y3, -3 to -5][Ego:-4 to -2, FSL]
And so
This is the only numbers that i need to replace in the file. The format of the PHASE 1 is standard the only values change are numbers I used:
for line in lines:
if 'PHASE 1:' in line:
print(line)
print(line.split('[')[2].split(','))
I could manage to get the following data: ['-', ' 1 to 3', ' -3 to -5]']
But I could not go beyond that How can take these values and replace them with my own and change the file for that. Any help would be appreciated