I know something similar has been asked before but I'm new to python and I can not find a solution for my problem:
What I want to do is this: 1. Open a file and read it line by line. (I already managed to do that) 2. Add something new after each line. (I want to combine this with an if statement later so that only specific lines will get edited)
My code:
#!/usr/bin/python3.4
file = open('testfile', 'r+')
readlinebyline = file.readline()
for i in range(0, len(readlinebyline)):
readlinebyline.write(' ' + 'checked')
print('done')
I want my testfile to look like this afterwards:
line1 checked
line2 checked
line3 checked
...
But instead it looks like this:
line1
line2
line3
checked checked checked
How do I get the program to stop after each line and then add something new to it?