遍历文件夹下所有的txt文件,然后读取内容,把内容中的"wo"替换成"我"
下面是我写的,供参考:
import os
path = r'D:\Desktop\e'
files = list(filter(lambda file:file[-4:]=='.txt',os.listdir(path)))
for file in files:
with open(path+os.sep+file,'r+') as f:
data = f.read()
data.replace('wo','我')
f.write(data)