gzip Python中的文件 [英] gzip a file in Python

查看:198
本文介绍了gzip Python中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用Python将文件gzip压缩.我正在尝试使用subprocss.check_call(),但它始终失败,并显示错误"OSError:[Errno 2]没有这样的文件或目录".我在这里尝试的内容有问题吗?是否有比使用subprocess.check_call更好的gzip文件压缩方式?

I want to gzip a file in Python. I am trying to use the subprocss.check_call(), but it keeps failing with the error 'OSError: [Errno 2] No such file or directory'. Is there a problem with what I am trying here? Is there a better way to gzip a file than using subprocess.check_call?

from subprocess import check_call

def gZipFile(fullFilePath)
    check_call('gzip ' + fullFilePath)

谢谢!

推荐答案

尝试一下:

check_call(['gzip', fullFilePath])

取决于您对这些文件的数据的处理方式,Skirmantas的链接为 http://docs.python. org/library/gzip.html 可能也有帮助.请注意页面底部附近的示例.如果您不需要访问数据,或者您的Python代码中没有数据,那么执行gzip可能是最干净的方法,因此您不必在Python中处理数据.

Depending on what you're doing with the data of these files, Skirmantas's link to http://docs.python.org/library/gzip.html may also be helpful. Note the examples near the bottom of the page. If you aren't needing to access the data, or don't have the data already in your Python code, executing gzip may be the cleanest way to do it so you don't have to handle the data in Python.

这篇关于gzip Python中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆