作业8
1、通用文件copy工具实现
file_path = input('请输入要复制的文件路径:').strip()
copy_path = input('请输入新文件的路径:').strip()
with open(file_path,mode='rb')as f,open(copy_path,mode='wb') as f1:
while True:
line = f.read(1024)
if len(line) == 0:
break
f1.write(line)
2.基于seek控制指针移动,测试r+、w+、a+模式下的读写内容
with open("b.txt","r+",encoding="utf-8") as f :
print(f.read())
f.seek(5,0)
print(f.tell())
f.write("bbb")
print(f.read())
with open("b.txt",wr+",encoding="utf-8") as f :
print(f.read())
f.seek(5,0)
print(f.tell())
f.write("bbb")
print(f.read())
with open("b.txt","a+",encoding="utf-8") as f :
print(f.read())
f.seek(5,0)
print(f.tell())
f.write("bbb")
print(f.read())
3.tail -f access.log程序实现

浙公网安备 33010602011771号