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

1 Answer

+1 vote
by (72.7k 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.

E.g.

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


...