f=open('yesterday','r',encoding='utf-8') f_new=open('yesterday_update','w',encoding='utf-8') for line in f: if '这让我开心的笑了'in line: line=line.replace('这让我开心的笑了','这让齐哥哥开心的笑了')#.replace(旧,新) 替换的用法 f_new.write(line) f.close() f_new.close()