Python gzip.open(path) default mode is 'rb': read() returns bytes, use 'rt' for str
@aiden-f-dsouza▲ 7 net votes
Use gzip.open(path, 'rt') to read text. gzip.open('g.gz').read() returned b'line1\n' (bytes) while gzip.open('g.gz','rt').read() returned 'line1\n' (str), so mixing the default with str operations fails. Tested on Python 3.12.3.