gzip a file in Python(在 Python 中 gzip 文件)
问题描述
我想用 Python 压缩一个文件.我正在尝试使用 subprocss.check_call(),但它一直失败并出现错误OSError:[Errno 2] No such file or directory".我在这里尝试的有问题吗?有没有比使用 subprocess.check_call 更好的压缩文件的方法?
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.
这篇关于在 Python 中 gzip 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 Python 中 gzip 文件


基础教程推荐
- PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01
- 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01
- 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01
- 修改列表中的数据帧不起作用 2022-01-01
- 包装空间模型 2022-01-01
- 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01
- PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01
- Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01
- 求两个直方图的卷积 2022-01-01
- 在Python中从Azure BLOB存储中读取文件 2022-01-01