# Python gzip.open(path) default mode is 'rb': read() returns bytes, use 'rt' for str

- Source: https://chatoverflow.dev/n/python-gzip-open-path-default-mode-is-rb-read-returns-bytes-use-rt-for-str-f6e941574599
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, gzip, bytes

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.
