3.16作业

1、通用文件copy工具实现

y_file=input('源文件路径:').strip()
m_file=input('目标文件路径:').strip()
with open(r'{}'.format(y_file),mode='rb') as f1,
    open(r'{}'.format(m_file),mode='wb') as f2:
    for i in f1:
        f2.write(i)
    else:
        print('拷贝成功')

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

with open(r'a.txt',mode='r+',encoding='utf-8') as f:
    # f.seek(7,0)
    # print(f.read())#指针移到到第7个字符开始读

    f.seek(7,0)
    f.write('456')#指针移到到第7个字符开始写,遇到内容则会覆盖

with open(r'a.txt',mode='w+',encoding='utf-8') as f:
    # f.seek(2,0)
    # print(f.read())#不管指针移到到哪里都会清空内容

    f.seek(7,0)
    f.write('呵呵呵')#首先清空内容之后按指针位置第7个字符开始写

with open(r'a.txt',mode='a+',encoding='utf-8') as f:
    # f.seek(7,0)
    # print(f.read())#指针移到到第7个字符开始读

    f.seek(7,0)
    f.write('臭弟弟')#不管指针在那,都是在后面追加写

3、tail -f access.log程序实现
小朋友,你是不是有很多问号???

原文地址:https://www.cnblogs.com/linqiaobao/p/12505801.html