python - 如何使用 Python 解压缩 gz 文件

标签 python python-2.7 gzip

我需要将我从 FTP 站点下载的 gz 文件提取到本地 Windows 文件服务器。我为文件的本地路径设置了变量,我知道它可以被 GZIP mudle 使用。

我该怎么做? GZ 文件中的文件是一个 XML 文件。

最佳答案

import gzip
import shutil
with gzip.open('file.txt.gz', 'rb') as f_in:
    with open('file.txt', 'wb') as f_out:
        shutil.copyfileobj(f_in, f_out)

关于python - 如何使用 Python 解压缩 gz 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31028815/

相关文章:

python - 定义自定义 PyMC 发行版

python - 使用正则表达式从文本文件的每一行中删除子字符串

python - 在函数内的 for 循环上使用 tqdm 来检查进度

python - 使用 Python 和 BeautifulSoup 解析 HTML - 获取 <a> 标签内部和外部的文本

php - 如何使用 curl 和 php 发送 gziped xml 内容

python - Pandas - Groupby - 捕获列的第一个值 - 错误的输出

python - Elasticsearch python 客户端 : Getting the ES version through API call

python - 如何以不同的名称序列化 Marshmallow 字段

asp.net-mvc-4 - MVC4 捆绑 GZIP 和 header

c# - 读取压缩文件并写入新文件将不允许解压