zoukankan      html  css  js  c++  java
  • python学习,day5:内置模块(复制和压缩)

    复制用的shutil模块

    import shutil
    f1 = open('本节笔记.txt',encoding='utf-8')
    
    f2 = open("笔记2.txt",'w',encoding='utf-8')
    shutil.copyfileobj(f1,f2)    #复制内容,需提前打开文件名
    
    shutil.copyfile('笔记2.txt',"笔记3.txt")   #不需要打开,只需要输入文件名就能复制(内置了open程序)
    shutil.copystat('笔记2.txt',"笔记3.txt")   #只copy权限
    shutil.copy()    #文件和权限都copy
    
    shutil.copytree('test4','newtest4')   #整个目录复制
    shutil.rmtree('newtest4')    #删除目录
    shutil.move()   #移动文件
    shutil.make_archive("shutil_archive_test",'zip',r'C:UserslenovoPycharmProjectsjbsuccday5')  #压缩
    

      压缩用的 zipfile模块

    import  zipfile    #压缩的包
    
    z= zipfile.ZipFile('day5.zip','w')  #打开压缩
    
    z.write('t.py')                  #开始写入压缩包
    print("----------")              #可以做别的
    z.write('笔记2.txt')             #继续写入压缩包
    z.close()                        #关闭压缩
    
  • 相关阅读:
    vim 真是上瘾啊
    乐此不疲
    .vimrc .bashrc
    github
    隐藏c语言烦人的{ }
    linux mint console-setup
    samsung n143 brightness on linux mint
    荒漠甘泉——1月31日
    嵌入式 方向?
    python2与python3的区别
  • 原文地址:https://www.cnblogs.com/bbgoal/p/11359198.html
Copyright © 2011-2022 走看看