John Machin wrote: > new = line[:-1] + "===\n" To allow for cases where the last line in the file is not terminated [can happen], this should be: new = line.rstrip("\n") + "===\n" # assuming you want to fix the unterminated problem. Cheers, John