[New-bugs-announce] [issue45475] gzip fails to read a gzipped file (ValueError: readline of closed file)

minstrelofc report at bugs.python.org
Thu Oct 14 17:12:01 EDT 2021


New submission from minstrelofc <minstrelofc at gmail.com>:

Attempting to iterate over an opened gzip file raises a ValueError: readline of closed file

Behavior in Python 3.9.7:
Python 3.9.7 (default, Oct 13 2021, 09:08:19) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import gzip
>>> ll = [l for l in gzip.GzipFile(filename='data/UTF-8-test_for_gzip.txt.gz')]
>>> len(ll)
300


Behavior in Python 3.10.0 (and 3.11.0a1 is the same):
Python 3.10.0 (default, Oct 13 2021, 08:53:15) [GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import gzip
>>> ll = [l for l in gzip.GzipFile(filename='data/UTF-8-test_for_gzip.txt.gz')]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 1, in <listcomp>
ValueError: readline of closed file


This only happens when iterating directly over the GzipFile object. Using a with: statement has the correct behaviour in both 3.10 and 3.11:
>>> with gzip.GzipFile(filename='UTF-8-test_for_gzip.txt.gz') as input_file:
...     len(list(input_file))
... 
300

----------
files: UTF-8-test_for_gzip.txt.gz
messages: 403948
nosy: minstrelofc
priority: normal
severity: normal
status: open
title: gzip fails to read a gzipped file (ValueError: readline of closed file)
type: behavior
versions: Python 3.10, Python 3.11
Added file: https://bugs.python.org/file50358/UTF-8-test_for_gzip.txt.gz

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue45475>
_______________________________________


More information about the New-bugs-announce mailing list