Date3
进度条:
#Author:Brill import sys,time for i in range(50): sys.stdout.write("#") sys.stdout.flush() time.sleep(0.1)
文件修改:(未成功)
#Author:Brill f = open("yesterday2","r",encoding="utf-8") f_new = open("文件名","w",encoding="utf-8") for line in f : if "要改的内容" in line: line = line.replace("要改的内容","新的内容") f_new.write(line) f.close() f_new.close()
文件相关操作:
#Author:Brill #data = open("yesterday",encoding="utf-8").read() f = open("yesterday2",'a',encoding="utf-8") f.write("When I was young I listen to the radio.\n") data = f.read() print("-----read----",data) f.close() f = open("yesterday2",'r',encoding="utf-8") for index,line in enumerate(f.readlines()): print(line.strip()) if index == 9: print("-------------I am middle-------------") continue print(line.strip()) #for i in range(5): # print(f.readline()) f = open("yesterday2",'r',encoding="utf-8") count = 0 for line in f : if count == 9: print("------------------I am you----------------") count +=1 continue print(line) count +=1 f = open("yesterday2",'r',encoding="utf-8") print(f.tell()) print(f.readline()) print(f.readline()) print(f.readline()) print(f.tell()) f.seek(10) print(f.readline()) print(f.encoding) print(f.fileno()) print(f.flush()) print(f.buffer) print(dir(f)) f.close() f = open("yesterday2","a",encoding="utf-8") f.seek(10) f.truncate(10) f = open("yesterday2","r+",encoding="utf-8") print(f.readline()) print(f.readline()) print(f.readline()) f.write("------------Hello--------------------") print(f)
你只管努力,其他的交给天意~