美文网首页
python 解压7z分卷压缩包

python 解压7z分卷压缩包

作者: RedB | 来源:发表于2020-07-21 18:21 被阅读0次

最近在用python解压7z,偶尔遇到.7z.001、.7z.002这种分卷压缩的情况,而解压库默认不支持这种。经过一番研究,研究出了如下解决办法。

第一步:合并分卷压缩包

# 合并多个7z分卷文件
filenames = ['example.7z.001', 'example.7z.002']
with open('result.7z', 'ab') as outfile:  # append in binary mode
    for fname in filenames:
        with open(fname, 'rb') as infile:  # open in binary mode also
            outfile.write(infile.read())

第二步:解压合并后的7z

此处推荐使用py7zr这个库,亲测好用,更新也非常及时(官网:https://github.com/miurahr/py7zr

import py7zr
with py7zr.SevenZipFile('result.7z', mode='r') as z:
    z.extractall()

相关文章

网友评论

      本文标题:python 解压7z分卷压缩包

      本文链接:https://www.haomeiwen.com/subject/ozrwkktx.html