Message403948
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 |
|
Date |
User |
Action |
Args |
2021-10-14 21:12:01 | minstrelofc | set | recipients:
+ minstrelofc |
2021-10-14 21:12:01 | minstrelofc | set | messageid: <1634245921.58.0.043840382812.issue45475@roundup.psfhosted.org> |
2021-10-14 21:12:01 | minstrelofc | link | issue45475 messages |
2021-10-14 21:12:01 | minstrelofc | create | |
|