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

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

问题描述

我需要将我从 FTP 站点下载的 gz 文件解压缩到本地 Windows 文件服务器.我为文件的本地路径设置了变量,我知道 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天全站免登陆