2013-01-08 41 views
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() 

任何帮助,你可以给予将不胜感激。

回答

4

使用

open(destfile,"wb") 

写在二进制模式的文件。

+0

+1不存在二进制模式写入可能是问题。 – hughdbrown

+0

完美工作。谢谢! –