python没有使用gzip读取gzip文件
我想做一个托卡尼装置,我有一个文件,我想用gzip读取。但它给出了以下错误:python没有使用gzip读取gzip文件,python,gzip,Python,Gzip,我想做一个托卡尼装置,我有一个文件,我想用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.fram
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'# ')
该文件是一个.txt.gz文件您应该尝试最简单的调试技术:打印您试图使用的值 无论如何,如果您这样做了,您将看到
sys.argv[0]
不是您在运行代码的命令后放在命令行上的文件名参数,即sys.argv[1]
因此,改变:
file = sys.argv[0]
致:
谢谢你!确实是这样!
file = sys.argv[0]
file = sys.argv[1]
print( “Reading from file”,file )