标签: py7zlib

如何从7z压缩的文本文件中读取?

我想从csv(文本)文件中逐行读取(在Python 2.7中),该文件是7z压缩的.我不想解压缩整个(大)文件,而是要对行进行流式处理.

我尝试pylzma.decompressobj()失败了.我收到数据错误.请注意,此代码尚未逐行读取:

input_filename = r"testing.csv.7z"
with open(input_filename, 'rb') as infile:
    obj = pylzma.decompressobj()
    o = open('decompressed.raw', 'wb')
    obj = pylzma.decompressobj()
    while True:
        tmp = infile.read(1)
        if not tmp: break
        o.write(obj.decompress(tmp))
    o.close()
Run Code Online (Sandbox Code Playgroud)

输出:

    o.write(obj.decompress(tmp))
ValueError: data error during decompression
Run Code Online (Sandbox Code Playgroud)

python 7zip stream python-2.7 py7zlib

12
推荐指数
1
解决办法
7696
查看次数

标签 统计

7zip ×1

py7zlib ×1

python ×1

python-2.7 ×1

stream ×1