I write this code:
f = open('example.txt','r')
lines = f.readlines()
for i, line in enumerate(f):
if i < 3:
lines = ['LC '+line for line in lines]
with open('./example.txt', 'w') as f:
f.writelines(lines)
f.close()
elif i < 5:
lines = ['LB '+line for line in lines]
with open('./example.txt', 'w') as f:
f.writelines(lines)
f.close()
elif i > 6:
break
f.close()
I have a file with 11 lines. I want to write something in the start from every line. The word is different for the 3 first line and different for other 2. Could you help me what am I doing wrong?
might do the trick