f=open('yesterday','r',encoding='utf-8') f_new=open('yesterday2','w',encoding='utf-8') for line in f: if '我从未停下脚步去思考生命的意义' in line: line=line.replace('我从未停下脚步去思考生命的意义','qiangql从未停下脚步去思考生命的意义') f_new.write(line) f.close() f_new.close()