I am trying to replace some text in a file with a value. Everything works fine, but when I look at the file after it is finished, a new (empty) line appears after each line in the file. Is there something I can do to prevent this from happening.
Here is the code I have:
import fileinput for line in fileinput.FileInput("testfile.txt",inplace=1): line = line.replace("newhost",host) print line
Thanks Aaron
python file replace text
Aaron
source share