gzip模块作用:
为GNU zip文件提供了一个类似的接口,它使用zlib来压缩和解压数据。
1、写压缩gzip文件
#!/usr/bin/env python3 # encoding: utf-8 import gzip import io import os out_file_name = "example.text.gz" with gzip.open(out_file_name, 'wb') as output: with io.TextIOWrapper(output, encoding='utf-8') as enc: enc.write('test gzip content') print(out_file_name, '包含的大小:{}bytes'.format(os.stat(out_file_name).st_size)) os.system('file -b --mime {}'.format(out_file_name))