如何使用Python解压缩GZ文件 [英] How to unzip gz file using Python

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

问题描述

我需要提取从FTP站点下载到本地Windows文件服务器的gz文件.我已经为文件的本地路径设置了变量,并且我知道GZIP混乱可以使用它.

I need to extract a gz file that I have downloaded from an FTP site to a local Windows file server. I have the variables set for the local path of the file, and I know it can be used by GZIP muddle.

我该怎么做? GZ文件中的文件是XML文件.

How can I do this? The file inside the GZ file is an XML file.

推荐答案

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解压缩GZ文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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