0

我正在编写一个程序,该程序需要从设定的位置下载其他程序。当我在 Mac OS X 上测试时,我可以毫无问题地下载和运行这些程序,但是当我在 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()

您可以提供的任何帮助将不胜感激。

4

1 回答 1

4

利用

open(destfile,"wb")

以二进制模式写入文件。

于 2013-01-08T06:52:47.687 回答