Is it possible in Python to replace the content of a line in a file by its index number?
Would something like a line.replace to do this procedure?
Is it possible in Python to replace the content of a line in a file by its index number?
Would something like a line.replace to do this procedure?
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)