3.16作业
#1、通用文件copy工具实现 # file_path = input('请输入源文件路径:').strip() # # copy_path = input('复制后文件的路径:').strip() # # with open(r'%s'%file_path,mode='rb') as f1,\ # # open(r'%s'%copy_path,mode='wb') as f2: # # for item in f1: # # f2.write(item) #2、基于seek控制指针移动,测试r+、w+、a+模式下的读写内容 r+模式: with open(r'kkk.txt',mode='r+',encoding='utf-8') as f: print(f.read()) f.seek(3,0) print(f.tell()) f.write('345') f.seek(0,0) print(f.read()) w+模式: with open(r'kkk.txt',mode='w+',encoding='utf-8') as f: print(f.read()) f.seek(3,0) print(f.tell()) f.write('123') f.seek(0,0) print(f.read()) a+模式: with open(r'kkk.txt',mode='a+'