问题
I'm trying to open a password protected zip file in Python. However, I'm completely stuck!
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)
回答1:
From https://docs.python.org/2/library/zipfile.html:
ZipFile.extractall([path[, members[, 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.
Works on Python 3 too: https://docs.python.org/3/library/zipfile.html
来源:https://stackoverflow.com/questions/29631629/how-to-open-password-protected-zip-file-in-python-3