PyDocs

Nav

Data Compression and Archiving

open

gzip

function (source)
  • open(filename, mode='rb', compresslevel=6, encoding=None, errors=None, newline=None)
Open a gzip-compressed file in binary or text mode.

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 "r", "rb", "w", "wb", "x", "xb", "a" or "ab"
for binary mode, or "rt", "wt", "xt" or "at" for text mode.  The default
mode is "rb", and the default compresslevel is 6.

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 3.3, 3.4, 3.6, 3.15
  • 3.3: Added support for filename being a file object, support for text mode, and the encoding, errors and newline arguments.
  • 3.4: Added support for the 'x', 'xb' and 'xt' modes.
  • 3.6: Accepts a path-like object.
  • 3.15: The default compression level was reduced to 6 (down from 9). It is the default level used by most compression tools and a better tradeoff between speed and performance.
0 Examples
No examples for gzip/open.
See Also
No see-alsos for gzip/open
0 Notes
No notes for open