gzip a file in Python
There is a module gzip. Usage: Example of how to create a compressed GZIP file: import gzip content = b”Lots of content here” f = gzip.open(‘/home/joe/file.txt.gz’, ‘wb’) f.write(content) f.close() Example of how to GZIP compress an existing file: import gzip f_in = open(‘/home/joe/file.txt’) f_out = gzip.open(‘/home/joe/file.txt.gz’, ‘wb’) f_out.writelines(f_in) f_out.close() f_in.close() EDIT: Jace Browning’s answer using … Read more