我在网上搜索得很高,但仍无法找到解决上述问题的方法.有没有人知道为什么以及如果可以这样做?
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)
解决方法:
因为你错了. :)从docs:
07001.07002([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.
所以你应该为ZipFile对象调用这个函数,而不是静态方法.并且您不应该将归档名称作为第一个参数传递.