Python suggest change



This module provides a simple interface to compress and decompress files just like the GNU programs gzip and gunzip would.

The data compression is provided by the zlib module.

The gzip module provides the GzipFile class which is modeled after Python’s File Object. The GzipFile class reads and writes gzip-format files, automatically compressing or decompressing the data so that it looks like an ordinary file object.

Read and write GNU zip files

import gzip
import os

outfilename = 'example.txt.gz'
output =, 'wb')
    output.write('Contents of the example file go here.\n')

print outfilename, 'contains', os.stat(outfilename).st_size, 'bytes of compressed data'
os.system('file -b --mime %s' % outfilename)

Save it as 1gzip_write.py1.Run it through terminal.

$ python

application/x-gzip; charset=binary
example.txt.gz contains 68 bytes of compressed data

Feedback about page:

Optional: your email if you want me to get back to you:

Table Of Contents
32 Set
46 Enum
105 Stack
119 Mixins
121 ArcPy
127 Arrays
139 Neo4j
141 Curses
146 heapq
155 Audio
156 pyglet
158 ijson
161 Flask
164 pygame
167 Gzip
168 ctypes
187 shelve
  ↑ ↓ to navigate     ↵ to select     Esc to close