在 Python 中解压文件 [英] Unzipping files in Python

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

问题描述

我通读了 zipfile 文档,但无法理解如何解压缩文件,只能理解如何压缩文件.如何将 zip 文件的所有内容解压缩到同一目录中?

I read through the zipfile documentation, but couldn't understand how to unzip a file, only how to zip a file. How do I unzip all the contents of a zip file into the same directory?

推荐答案

import zipfile
with zipfile.ZipFile(path_to_zip_file, 'r') as zip_ref:
    zip_ref.extractall(directory_to_extract_to)

差不多就是这样!

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

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