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')**
您将在XML文件而不是目标文件上构建Archive7z。
要更正您的代码:将i
中的o
替换为s = py7zlib.Archive7z(i)
,将s
中的i
替换为tmp = s.read(65536)
。