0
我正在編寫一個程序,需要從設置的位置下載其他程序。我可以下載並沒有問題,運行這些程序,當我在Mac OS X測試,但是當我下載並解壓縮在Windows中的文件,它給我的錯誤:在Python中解壓縮EXE文件會導致與Windows不兼容錯誤
The version of this file is not compatible with the version of Windows you are running.
然後描述我如何去檢查無論我需要x86還是x64版本。我使用Winrar解壓縮了相同的文件,並且所包含的程序運行順暢,所以我確信它是我的代碼。
def _unzip_(self,file,destdir):
print "Unzipping %s to %s" % (file,destdir)
z = zipfile.ZipFile(file)
for f in z.namelist():
# Zipfiles store paths internally using a forward slash. If os.sep
# is not a forward slash, then we will compute an incorrect path.
# Fix that by replacing all forward slashes with backslashes if
# os.sep is a backslash
if os.sep == "\\" and "/" in f:
destfile = os.path.join(destdir,f.replace("/","\\"))
else:
destfile = os.path.join(destdir,f)
if destfile.endswith(os.sep):
if not os.path.exists(destfile):
os.makedirs(destfile)
else:
file = open(destfile,"w")
file.write(z.read(f))
file.close()
z.close()
任何幫助,你可以給予將不勝感激。
+1不存在二進制模式寫入可能是問題。 – hughdbrown
完美工作。謝謝! –