在Python中读入zlib文件会导致“不正确的头检查”

2024-05-14 20:30:49 发布

您现在位置:Python中文网/ 问答频道 /正文

Possible Duplicate:
uncompressing tar.Z file with python?

我试图读取一个压缩的zlib,以便直接访问包含的HDF文件中的数据(使用pyhdf)。但是,我总是收到一条错误消息。这是file。在

import zlib
file = open('3B42.20070101.00.7A.HDF.Z','rb')
data = zlib.decompress(file.read())

>> error: Error -3 while decompressing data: incorrect header check

我检查了其他几种方法(例如。gzip.open/gzip.zlib)但似乎什么都不起作用。你有什么建议吗?在


Tags: 文件数据data错误withtaropenfile
1条回答
网友
1楼 · 发布于 2024-05-14 20:30:49

这不是zlib或gzip文件,它是由旧的Unix工具compress(从.Z扩展名可以看出)压缩的。命令行工具gzip/gunzip/zcat可以读取这些内容,但不能读取Pythongzip模块。你可以用管子:

from subprocess import Popen, PIPE

filename = "3B42.20070101.03.7A.HDF.Z"
f = Popen(["zcat", filename], stdout=PIPE).stdout

现在,f是一个可以用来读取文件的文件。在

相关问题 更多 >

    热门问题