我有这个简单的python函数,可以提取zip文件(独立于平台)
def unzip(source, target):
with zipfile.ZipFile(source , "r") as z:
z.extractall(target)
print "Extracted : " + source + " to: " + target
Run Code Online (Sandbox Code Playgroud)
这在Python 2.7中运行良好,但在Python 2.6中失败:
AttributeError: ZipFile instance has no attribute '__exit__':
Run Code Online (Sandbox Code Playgroud)
我发现这个建议需要升级2.6 - > 2.7 https://bugs.launchpad.net/horizon/+bug/955994
但是可以将上面的代码移植到Python 2.6并仍然保持跨平台吗?