使Python 2.7代码与Python 2.6一起运行
发布于 2021-01-29 14:58:04
我有这个简单的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一起使用,并且仍然保持跨平台运行?
关注者
0
被浏览
87
1 个回答