+1 vote
in Programming Languages by (58.9k points)
How can I open and read a gzip-compressed file in text mode using Python?

1 Answer

+1 vote
by (71.8k points)
selected by
Best answer

To open a gzip-compressed file in python, you can use gzip.open() function with "rt" as the mode argument.


with gzip.open(inpfile, "rt") as fin:

The mode argument can be any of 'r', 'rb', 'a', 'ab', 'w', 'wb', 'x' or 'xb' for binary mode, or 'rt', 'at', 'wt', or 'xt' for text mode. The default is 'rb'.

Related questions