ⅩⅡ:作业

1、通用文件copy工具实现

src_file=input('源文件路径: ').strip()
dst_file=input('目标文件路径: ').strip()
with open(r'%s' %src_file,mode='rb') as read_f,open(r'%s' %dst_file,mode='wb') as write_f:
    for line in read_f:
        print(line)
        write_f.write(line)

2、基于seek控制指针移动,测试r+、w+、a+模式下的读写内容

with open(r'a.txt', 'r+t') as f:
    print(f.read()) 
    f.seek(5, 0)  
    print(f.tell()) 
    f.write('aaa')
    f.seek(0, 0)
    print(f.read())

with open(r'a.txt', 'w+t') as f:
    print(f.read()) 
    f.seek(5, 0)  
    print(f.tell()) 
    f.write('aaa')
    f.seek(0, 0)
    print(f.read())

with open(r'a.txt', 'a+t') as f:
    print(f.read())
    f.seek(5, 0)
    print(f.tell())
    f.write('aaa')
    f.seek(0, 0)
    print(f.read())

3、tail -f access.log程序实现

posted @ 2020-03-16 22:12  迷路的玖儿  阅读(129)  评论(0)    收藏  举报