I am trying to write out text to the new file without minor change in the text at “position 12” to “at position”+ newPosition +”was at 12”.
Would this be possible?
I tried writing to the end of the line but it wrote out as a new line instead of concatenate at the end
My ‘line’ is >Q952U6 | at position 12 | start= 519, end= 541 | description: E530K | LUSC Z52178 M2536nse_231ation T20A-18-3409 Q952U6 E530K
with open(filename) as f:
with open(fileoutput,'w') as fOut:
for line, line2 in itertools.izip_longest(f, f, fillvalue=''):
tokenizer=int(line.split()[4])
newPosition = get_new_indexs(tokenizer, str(line2))
fOut.write(line+' | new position ='+str(newPosition))
When you iterate through a file, each line will include the newline at the end. You have to strip it off the end. You can do it like this:
Or, in your specific case, you could do: