我在网上搜索了很久,但仍然找不到解决上述问题的方法。有人知道为什么吗?如果知道,能告诉我如何解决吗?
psw="dg"
ZipFile.extractall("data.zip", None, psw)
我遇到的错误:
TypeError: unbound method extractall() must be called
with ZipFile instance as first argument (got str instance instead)
我在网上搜索了很久,但仍然找不到解决上述问题的方法。有人知道为什么吗?如果知道,能告诉我如何解决吗?
psw="dg"
ZipFile.extractall("data.zip", None, psw)
我遇到的错误:
TypeError: unbound method extractall() must be called
with ZipFile instance as first argument (got str instance instead)
所以你应该对ZipFile对象调用该函数,而不是作为静态方法调用。并且你不应该将存档名称作为第一个参数传递。 :) 这样做就可以了:ZipFile.extractall([path[, members[, pwd]]])
将zip文件中的所有成员解压到当前工作目录。path参数指定一个不同的目录来进行提取。members参数是可选的,并且必须是namelist()返回列表的子集。pwd参数是用于加密文件的密码。
from zipfile import ZipFile
with ZipFile('data.zip') as zf:
zf.extractall(pwd='dg')
编辑,在更新的版本中使用:
zf.extractall(pwd=b'dg')
b
。这是正确的方式。 - nainometerfrom zipfile import ZipFile
str_zipFile = 'FileZip.zip'
str_pwd= 'xxxx'
with ZipFile(str_zipFile) as zipObj:
zipObj.extractall(pwd = bytes(str_pwd,'utf-8'))
有些文件的来源不明,并且提取时间很长。
例如,如果已经提取了60秒或者时间已经过去,我想删除原始文件以取消操作。
import pyzipper
with pyzipper.AESZipFile('test.zip', 'r', compression=pyzipper.ZIP_LZMA, encryption=pyzipper.WZ_AES) as extracted_zip:
extracted_zip.extractall(pwd=str.encode("@apkclub"))
os.remove(test.zip)