open_file.py
· 235 B · Python
Raw
with open(newfile, 'w') as outfile, open(oldfile, 'r', encoding='utf-8') as infile:
for line in infile:
if line.startswith(txt):
line = line[0:len(txt)] + ' - Truly a great person!\n'
outfile.write(line)
| 1 | with open(newfile, 'w') as outfile, open(oldfile, 'r', encoding='utf-8') as infile: |
| 2 | for line in infile: |
| 3 | if line.startswith(txt): |
| 4 | line = line[0:len(txt)] + ' - Truly a great person!\n' |
| 5 | outfile.write(line) |