好多错误啊
作者:互联网
# 新建一个txt文件,在将他重命名,写入名字,改第二个相同的字符名 # lst = ["周杰伦", "张杰伦", "李杰伦", "猪八戒"] # f = open("1.txt", mode="w", encoding="utf-8") # for line in lst: # f.write(line + "\n") # f.close() with open("1.txt", mode="r", encoding="utf-8") as f1, \ open("1.txt", mode="w", encoding="utf-8") as f2: print(f1.readlines(), f2.readlines()) # for ln in f1: # if ln.startswith("张"): # ln = ln.strip() # ln = ln.replace("张", "周") # f2.write(ln) # 把文件总的内容写入f2文件中 # f2.write("\n") # f1 = open("1.txt", mode="r", encoding="utf-8") # print(f1.readlines()) # f1.close() # lst1 = list() # with open("1.txt", mode="r", encoding="utf-8") as f2, \ # open("1.txt", mode="w", encoding="utf-8") as f3: # for line1 in f2: # print(line1) # lin = line1.find("杰") # n = line1[lin] # print(n) # if line1.startswith("张"): # line1 = line1.replace("张", "长") # f3.write(line1) # # for a in lst1: # # a.replace(n, "1") # # lst1.append(line1) # print(line1) # else: # print("不存在") # print(lst1) # print(type(line1)) # a = "你好啊" # a1 = a.replace("好", "11") # print(a1) # f.close() # import os # os.remove("1.txt")
标签:f1,f2,错误,ln,line1,好多,print,txt 来源: https://www.cnblogs.com/acwecc/p/16287559.html