python的gzip库使用方法
解压gzip文件示例:
import gzip
f = gzip.open('file.txt.gz', 'rb')
file_content = f.read()
f.close()
创建gzip文件:
import gzip
content = "Lots of content here"
f = gzip.open('file.txt.gz', 'wb')
f.write(content)
f.close()
gzip压缩现有文件:
import gzip
f_in = open('file.txt', 'rb')
f_out = gzip.open('file.txt.gz', 'wb')
f_out.writelines(f_in)
f_out.close()
f_in.close()
更多内容请见:
https://docs.python.org/2/library/gzip.html