I am trying to insert multiple lines in a string which I have created with readlines() in python. I did many hours of debugging on it but I can't figure out what the problem is.
I have a number i of servers which is defined previously. 'data' is a string which includes my textdocument and I have a function 'get_line' which searches the string for the keyword 'Queue1 Position' and returns the line. In my example the line is 82.
...
data = cfg.readlines()
...
#Queue
i = int(gwi["Server"][0]) #Number of Servers
line_idx=get_line(data,'Queue1 Position')
for x in range(1,i+1):
if x==1:
data[line_idx] = ('Queue'+str(x)+' Position { 1.500000 '+str(1.100000-x+1)+' 0.000000 m }\n'+'Queue'+str(x)+
' Points { { 1.500 '+str(0.700-x+1)+' 0.000 m } { 2.500 '+str(0.700-x+1)+' 0.000 m } }\n\n')
print(line_idx) #test
else:
line_idx = line_idx + 1
data[line_idx] = ('Queue'+str(x)+' Position { 1.500000 '+str(1.100000-x+1)+' 0.000000 m }\n'+'Queue'+str(x)+
' Points { { 1.500 '+str(0.700-x+1)+' 0.000 m } { 2.500 '+str(0.700-x+1)+' 0.000 m } }\n\n')
print(line_idx) #test
My Document which I edit looks like that at the beginning.
When I run my code the cfg- file looks like that. 'Server1 NextComponent { EntitySink1 }' is cut.
But when I run my code the result should be like that.
Is it even possible to solve this problem with a for loop? Maybe there is another solution.