python Python中使用的gzip压缩文件

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python Python中使用的gzip压缩文件相关的知识,希望对你有一定的参考价值。

import gzip

def gzip_file(f):
    print 'compress file: %s' % f
    if not file_exists(f):
        return ''
    z = f + '.gz'
    try:
        fin = open(f, 'rb')
        fout = gzip.open(z, 'wb')
        fout.writelines(fin)
        fout.close()
        fin.close()
    except Exception, e:
        print 'compress file error: %s' % e
        return ''
    return z

以上是关于python Python中使用的gzip压缩文件的主要内容,如果未能解决你的问题,请参考以下文章