1import gzip
2f_in = open('/home/joe/file.txt')
3f_out = gzip.open('/home/joe/file.txt.gz', 'wb')
4f_out.writelines(f_in)
5f_out.close()
6f_in.close()
1import gzip
2import shutil
3with open('/home/joe/file.txt', 'rb') as f_in:
4 with gzip.open('/home/joe/file.txt.gz', 'wb') as f_out:
5 shutil.copyfileobj(f_in, f_out)
6