gzip.open(filename, mode='rb', compresslevel=9, encoding=None, errors=None, newline=None)
Open a gzip-compressed file in binary or text mode, returning a file object.
The filename argument can be an actual filename (a str
or bytes
object), or an existing file object to read from or write to.
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'
.
The compresslevel argument is an integer from 0 to 9, as for the GzipFile
constructor.
For binary mode, this function is equivalent to the GzipFile
constructor: GzipFile(filename, mode, compresslevel)
. In this case, the encoding, errors and newline arguments must not be provided.
For text mode, a GzipFile
object is created, and wrapped in an io.TextIOWrapper
instance with the specified encoding, error handling behavior, and line ending(s).
Changed in version 3.3: Added support for filename being a file object, support for text mode, and the encoding, errors and newline arguments.
Changed in version 3.4: Added support for the 'x'
, 'xb'
and 'xt'
modes.
Please login to continue.