python - 如何让Python 2.4.3具有提取Python 2.6中引入的ZIP文件的能力?

标签 python zip

ZipFile.extract(member[, path[, pwd]]) 是 Python 2.6 中引入的新功能。由于某种原因,我需要在 Python 2.4.3 中实现 ZipFile.extract(2.4.3 无法处理 ZipFile,只能处理一些属性)。

我正在考虑显式导入 zipfile.py在我需要使用 extract 函数的 python 脚本中。

我的考虑是,我不知道zipfile.py中是否有任何与Python 2.4.3标准不兼容的新语法或新功能。

还有其他方法吗?

提前谢谢您!

最佳答案

ZipFile.extract()可以使用 ZipFile.open() 进行模拟, open() ,和shutil.copyfileobj() 。该功能甚至可以被猴子补丁到 ZipFile 中。基于所使用的 Python 版本。

if PythonVersion < 2.6: # obviously not how it's done
  def myextract(self, member, path=None, pwd=None):
     ...
  zipfile.ZipFile.extract = myextract

关于python - 如何让Python 2.4.3具有提取Python 2.6中引入的ZIP文件的能力?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14653427/

相关文章:

python - 在 Spyder 中处理折叠

windows - 如何在多个 zip 文件中添加一个文件?

python - 如何以支持 autograd 的方式围绕其中心旋转 PyTorch 图像张量?

python - 导入错误 : "flask_sqlalchemy" could not be resolved

Python SequenceMatcher 开销 - 100% 的 CPU 使用率和非常缓慢的处理

python - 如何删除 tensorflow 中的连续重复项?

Maven - 依赖于组装的 zip

c++ - 用于 C/C++ 的可移植 zip 库(不是应用程序)

oracle - 使用 Oracle 存储过程压缩

java - 我怎样才能保护自己免受 zipper 炸弹的伤害?