zlib [docs] implements the compression used by gzip, but not the file format. Instead, you should use the gzip module [docs], which itself uses zlib.
import gzip
s = '...'
with gzip.open('/tmp/data', 'w') as f:
f.write(s)
zlib [docs] implements the compression used by gzip, but not the file format. Instead, you should use the gzip module [docs], which itself uses zlib.
import gzip
s = '...'
with gzip.open('/tmp/data', 'w') as f:
f.write(s)