python的gzip库使用方法

来源:互联网 发布:杨凯黄金分割线源码 编辑:程序博客网 时间:2024/05/17 16:15

解压gzip文件示例:

import gzipf = gzip.open('file.txt.gz', 'rb')file_content = f.read()f.close()

创建gzip文件:

import gzipcontent = "Lots of content here"f = gzip.open('file.txt.gz', 'wb')f.write(content)f.close()

gzip压缩现有文件:

import gzipf_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

0 0
原创粉丝点击