解压gzip文件:
import gzip
f = gzip.open('file.txt.gz', 'rb')
file_content = f.read()
f.close()1234
创建gzip文件:
import gzip
content = "Lots of content here"f = gzip.open('file.txt.gz', 'wb')
f.write(content)
f.close()12345
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()
众多python培训视频,尽在python学习网,欢迎在线学习!