相关疑难解决方法(0)

使用Python 2.6运行Python 2.7代码

我有这个简单的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/horizo​​n/+bug/955994

但是可以将上面的代码移植到Python 2.6并仍然保持跨平台吗?

python compatibility python-2.6 python-2.7

8
推荐指数
1
解决办法
5042
查看次数

标签 统计

compatibility ×1

python ×1

python-2.6 ×1

python-2.7 ×1