【发布时间】:2014-02-11 15:46:45
【问题描述】:
我有这个简单的 python 函数,可以提取一个 zip 文件(独立于平台)
def unzip(source, target):
with zipfile.ZipFile(source , "r") as z:
z.extractall(target)
print "Extracted : " + source + " to: " + target
这在 Python 2.7 上运行良好,但在 Python 2.6 上运行失败:
AttributeError: ZipFile instance has no attribute '__exit__':
我发现这个建议需要升级 2.6 -> 2.7 https://bugs.launchpad.net/horizon/+bug/955994
但是是否可以将上述代码移植到 Python 2.6 并仍然保持跨平台?
【问题讨论】:
标签: python python-2.7 compatibility python-2.6