如何在 Python 3 中打开受密码保护的 zip 文件 [英] How to open password protected zip file in Python 3

查看:37
本文介绍了如何在 Python 3 中打开受密码保护的 zip 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试用 Python 打开一个受密码保护的 zip 文件.然而,我完全卡住了!

I'm trying to open a password protected zip file in Python. However, I'm completely stuck!

我已经阅读了有关 zip 文件的 python 文档,但我找不到任何可以打开受密码保护的文件.

I've gone through the python documentation on zip files, but I can't find anything for opening one that is password protected.

有人能指出我正确的方向吗?

Could someone please point me in the right direction?

path = "some_file.zip"
password = "example123"

# How do I add the password parameter?
ZipFile.extractall(path)

推荐答案

来自 https://docs.python.org/2/library/zipfile.html:

ZipFile.extractall([path[, members[, pwd]]])

从存档中提取所有成员到当前工作目录.path 指定要提取到的不同目录.members 是可选的,必须是 namelist() 返回的列表的子集.pwd 是用于加密文件的密码.

Extract all members from the archive to the current working directory. path specifies a different directory to extract to. members is optional and must be a subset of the list returned by namelist(). pwd is the password used for encrypted files.

也适用于 Python 3:https://docs.python.org/3/图书馆/zipfile.html

Works on Python 3 too: https://docs.python.org/3/library/zipfile.html

这篇关于如何在 Python 3 中打开受密码保护的 zip 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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