FormatError:不是7z文件

问题描述 投票:0回答:1
with open (sourcefile,'rb') as i:
    with open (targetfile,'wb') as o:
        i.seek(0)
        s = py7zlib.Archive7z(i)
        while True:
            tmp = s.read(65536)
            if tmp :
                o.write(tmp)
                continue
            else:
                break

我收到错误FormatError:不是7z文件s = py7zlib.Archive7z(i)

[当我在Windows 7上运行的python 3.3中使用pylzma压缩文件时,

我尝试压缩的文件是XML文件。即使这样也不起作用:

with open (sourcefile,'rb') as i:
    with open (targetfile,'wb') as o:
        i.seek(0)
        s = py7zlib.Archive7z(o)
        while True:
            tmp = s.read(65536)
            if tmp:
                o.write(tmp)
                continue
            else:
                break

错误:

UnsupportedOperation: read
**raise FormatError('not a 7z file')**
python python-3.x 7zip
1个回答
0
投票

您将在XML文件而不是目标文件上构建Archive7z。

要更正您的代码:将i中的o替换为s = py7zlib.Archive7z(i),将s中的i替换为tmp = s.read(65536)

© www.soinside.com 2019 - 2024. All rights reserved.