私は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()
出力:あなたは、Python 3.3+を使用していた場合
o.write(obj.decompress(tmp))
ValueError: data error during decompression
は、なぜあなたはあなたのコードとサンプルファイルを投稿しませんか? –
.7zファイルは、複数のファイルを含むことができるコンテナ(アーカイブ)なので、読みたい 'testing.7z'内のファイルの名前は何ですか? – martineau
@martineau、testing.csv – Yariv