我想从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)