with open('factory2.txt') as sf, open('target1.txt', 'w') as tf:
i = -1
for line in sf:
if line.startswith('tmpobjid2a'):
i += 1
tf.write(line.replace('tmpobjid2a', f'tmpobjid2a[{i}]'))
I am trying to use this but the i value isn't changing at all, what am I doing wrong here? The i value is just saying as -1 for all the lines. Even though it's passing lines that start with 'tmpobjid2a'