Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/343.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python没有使用gzip读取gzip文件_Python_Gzip - Fatal编程技术网

python没有使用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

我想做一个托卡尼装置,我有一个文件,我想用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'# ')

该文件是一个.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 )