Python write()编写的文件无法';不要在窗口打开

Python write()编写的文件无法';不要在窗口打开,python,web.py,Python,Web.py,代码如下: #!/usr/bin/env python #-*-coding:utf-8 -*- import web urls=('/','index') class index: def GET(self): web.header("Content-Type","text/html; charset=utf-8") return """<html><head></head><body>

代码如下:

#!/usr/bin/env python
#-*-coding:utf-8 -*-

import web

urls=('/','index')

class index:
    def GET(self):
        web.header("Content-Type","text/html; charset=utf-8")
        return """<html><head></head><body>
        <form method="POST" enctype="multipart/form-data" action="">
        <input type="file" name="mainTable" />
        <br/>
        <input type="submit" />
        </form>
        </body></html>"""
    def POST(self):
        i=web.input(mainTable={})
        fout=open(".\\tables\\main.xls",'w')
        fout.write(i.mainTable.file.read())
        fout.close()
if __name__=="__main__":
    app=web.application(urls,globals())
    app.run()
#/usr/bin/env python
#-*-编码:utf-8-*-
导入web
URL=(“/”,“索引”)
类别索引:
def GET(自我):
标题(“内容类型”、“文本/html;字符集=utf-8”)
返回“”

""" def POST(自我): i=web.input(mainTable={}) fout=open(“.\\tables\\main.xls”,“w”) write(i.mainTable.file.read()) fout.close() 如果名称=“\uuuuu main\uuuuuuuu”: app=web.application(URL,globals()) app.run()
我把它放在linux服务器上,它工作了,一个excel文件成功上传(当然,路径格式必须更改),我可以下载它并用excel打开它

但当我把它放在Windows服务器上时,文件被上传了,但我无法打开它。excel显示文件已损坏。那么我的代码怎么了?

来自

默认情况下使用文本模式,该模式可以转换
'\n'
字符 在书写和阅读时返回平台特定的表示。 因此,在打开二进制文件时,应将
'b'
附加到模式 值以二进制模式打开文件,这将提高可移植性。 (即使在不处理二进制和二进制数据的系统上,附加
'b'
也很有用 不同的文本文件,用作文档。)

fout=open(".\\tables\\main.xls", 'wb')