我有這個簡單的Python函數,可以提取一個zip文件(獨立平臺)使得使用Python運行Python 2.7代碼2.6
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
但是,它可能端口上面的代碼WOR k與Python 2.6並仍然保持跨平臺?
對於zipfile模塊,上下文管理器「with」支持從python版本2.7.1 https://docs.python.org/2/library/zipfile.html嘗試不帶「with」的舊版本。 –