【发布时间】:2019-03-03 08:52:06
【问题描述】:
我正在尝试制作一个 tokanizer,我有一个我正在尝试使用 gzip 读取的文件。但它给出了以下错误:
Traceback (most recent call last):
File "extract_sends.py", line 14, in <module>
main()
File "extract_sends.py", line 12, in main
file_content = f.read()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/gzip.py", line 276, in read
return self._buffer.read(size)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/gzip.py", line 463, in read
if not self._read_gzip_header():
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/gzip.py", line 411, in _read_gzip_header
raise OSError('Not a gzipped file (%r)' % magic)
OSError: Not a gzipped file (b'# ')
这是我的代码,我才刚刚开始,但如果 python 无法读取该文件,我就不远了。
import gzip
import sys
import re
def main():
file = sys.argv[0]
with gzip.open(file, 'rt') as f:
file_content = f.read()
main()
文件是 .txt.gz 文件
【问题讨论】: