#先读出来把文件
with open(r"C:\Users\william.tan\Desktop\1.txt", "r") as f:
files = f.readlines()
#再打开上面读出来的变量文件进行遍历,把需要的内容打出来改一下再写进去.
with open(r"C:\Users\william.tan\Desktop\1.txt","w") as f2:
for i in files:
if "/root" in i: #如果找到/root这行就把他改成aaaaaaaa再写入这行
i = "/aaaaaaaaaaaaa" + "\n" #一定要加换行符。
f2.write(i)
12-25