Skip to main content
1 of 2
user1114
  • 1
  • 1
  • 4
  • 13

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)