zoukankan      html  css  js  c++  java
  • Python学习————作业

    1、通用文件copy工具实现

    src_file = input("输入文件路径:").strip()
    new_file = input("输入新文件路径:").strip()
    with open(f'{src_file}', mode="rb") as f1, 
            open(f'{new_file}', mode="wb") as f2:
        for line in f1:
            f2.write(line)
    

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

    with open("a.txt", "r+", encoding="utf-8") as f:
        print(f.read())
        f.seek(6, 0)
        print(f.tell())
        f.write('1111
    222
    3333
    ')
        print(f.read())
    with open("a.txt", "w+", encoding="utf-8") as f:
        print(f.read())
        f.seek(6, 0)
        print(f.tell())
        f.write('1111
    222
    3333
    ')
        print(f.read())
    
    with open("a.txt", "a+", encoding="utf-8") as f:
        print(f.read())
        f.seek(6, 0)
        print(f.tell())
        f.write('1111
    222
    3333
    ')
        print(f.read())
    

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

    cmd = input("请输入b文件追加的信息:").strip()
    with open("b.txt", "a+t", encoding="utf-8") as f:
        f.write(cmd)
    with open("b.txt", "r", encoding="utf-8") as f:
        print(f.read())
    
  • 相关阅读:
    [ SDOI 2006 ] 保安站岗
    [ TJOI 2012 ] 防御
    [ ZJOI 2012 ] 灾难
    [ HNOI 2008 ] 玩具装箱
    「UER#2」信息的交换
    「UR#5」怎样跑得更快
    「UR#6」懒癌
    清华集训2014 做题记录
    「UR#5」怎样更有力气
    弦图及区间图学习笔记
  • 原文地址:https://www.cnblogs.com/x945669/p/12506251.html
Copyright © 2011-2022 走看看