Python——文件操作3——文件修改
#文件修改操作 #同时打开两个文件,边读边写 f = open('yesterday2','r',encoding='utf-8') f_1=open('yesterday3','w',encoding='utf-8') for line in f : if "hello" in line : line=line.replace("hello","你好!") f_1.write(line) f.close() f_1.close()
#文件修改操作 #同时打开两个文件,边读边写 f = open('yesterday2','r',encoding='utf-8') f_1=open('yesterday3','w',encoding='utf-8') for line in f : if "hello" in line : line=line.replace("hello","你好!") f_1.write(line) f.close() f_1.close()