[Solved] Python replace line by index number


If you wish to count iterations, you should use enumerate()

with open('fin.txt') as fin, open('fout.txt', 'w') as fout:
    for i, item in enumerate(fin, 1):
        if i == 7: 
            item = "string\n" 
        fout.write(item)

2

solved Python replace line by index number