zoukankan      html  css  js  c++  java
  • 20.03.17作业

    1、通用文件copy工具实现

    print("copy程序")
    src_file = input("初始源文件路径:>>>")
    copy_file = input("目标源文件路径:>>>")
    with open(r"{}".format(src_file),mode="rb") as f1,
        open(r"{}".format(copy_file),mode="wb") as f2:
        for line in f1:
            f2.write(line)
    print("copy结束,欢迎下次再次使用")

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

    # r+
    with open('d.txt',mode='r+b')as f1:
        f1.seek(2,0)
        print(f1.read().decode('utf-8'))
        f1.seek(6,1)
        f1.write('stop'.encode('utf-8'))
    # #w+
    with open('d.txt',mode='w+b')as f2:
        f2.seek(0,1)
        print(f2.read().decode('utf-8'))
        f2.seek(1,1)
        f2.write('add'.encode('utf-8'))
    #a+
    with open('d.txt',mode='a+b')as f3:
        f3.seek(-5,2)
        print(f3.read().decode('utf-8'))
        f3.seek(3,1)
        f3.write('fgrg'.encode('utf-8'))
        f3.seek(1,1)
        f3.write('dgdsd'.encode('utf-8'))

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

    import time
    with open("access.log",mode="rb") as f:
        f.seek(0,2)
        while True:
            line = f.readline()
            if len(line) ==0:
                time.sleep(1)
            else:
                print(line.decode("utf-8"),end=" ")
  • 相关阅读:
    培训是一种乐趣(3)
    JAVA多线程放号器
    西游记(2)
    Swing事件处理
    西游记
    Swing普通控件
    JAVA语言的BUG?
    Swing高级控件
    JavaBean属性拷贝
    JAVA排序汇总
  • 原文地址:https://www.cnblogs.com/zhangjinyi97/p/12509241.html
Copyright © 2011-2022 走看看