Python - zip壓縮模塊


# 導入壓縮模塊
import zipfile
# 查看當前模塊的功能
# help(zipfile)
'''
a.打開冰箱門(創建壓縮文件,並且打開)
    方法:z = ZipFile(file, mode="r", compression=ZIP_STORED, allowZip64=True)
        參數
                file:壓縮文件的路徑
                mode="r":設置操作文件的模式  r 讀取  w 寫入  a 追加模塊 x 抑或模式
                compression:設置壓縮模式
                            ZIP_STORED (no compression), ZIP_DEFLATED (requires zlib),
                            ZIP_BZIP2 (requires bz2) or ZIP_LZMA (requires lzma).                
                allowZip64:設置壓縮文件是否超過2個G
'''
zp = zipfile.ZipFile('./zip01.zip', 'w')
'''
b.把大象塞進去(把文件添加到壓縮文件當中)
    方法: write(self, filename, arcname=None, compress_type=None)
        參數
                filename:需要添加的文件
                arcname:在壓縮文件中的路徑和名稱 
'''
zp.write('./遞歸.py', 'm.py')
'''
c.把冰箱門關上(關閉壓縮文件)
'''
zp.close()


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM