#进度条import sys,time i=0 while i<=100: sys.stdout.write(‘*‘) sys.stdout.flush()#直接刷到内存 time.sleep(1) i+=1
with open(‘song‘,‘r+‘) as f: f.readline() a=f.tell() f.readline() b=f.tell() f.readline() f.seek(a)#若后面加入f.readline(),不管seek到哪里,f.write都在文件末尾添加。否则在seek的位置覆盖添加 f.write(‘this is added by fwrite\n‘)
#二进制读写 with open(‘song_write_wb‘,‘wb‘) as f: f.seek(10) f.write(‘this is added by fwrite\n‘.encode(encoding=‘utf-8‘))
时间: 2024-10-01 00:31:27