python-压缩多个文件到zip格式-zipfile包实例

import zipfile

def compress_attaches(files, out_name):
    f = zipfile.ZipFile(out_name, 'w', zipfile.ZIP_DEFLATED)
    for file in files:
        f.write(file)
    f.close() 
    
files = ['a.txt', 'K.result.xlsx']
compress_attaches(files, '0731-test.zip')

已测试,可以正确压缩。

你可能感兴趣的:(python大法好,python)