def repalcebytext(address, ori_str, target_str):
all_data = ''
with open(address, 'r+', encoding="UTF-8") as f:
for line in f.readlines():
if line.find(ori_str) != -1:
line = target_str
all_data += line
f.close()
with open(address, 'r+', encoding="UTF-8") as f:
f.truncate()
f.write(all_data)
f.close()
网友评论