怎么设置python,使得由sys.stdout.write输出的是二进制格式
我在写一段web 服务器的代码
当浏览器请求 图象等格式的时候,需要向浏览器传送二进制文件
也就是需要向标准输出流中 传递从图片读出来二进制格式数据
区别在 '\r\n'上,我现在是在windows平台上开发,必须设置一下流的输出方式
但是不知道怎么设置才行。
我用的python 2.5
以前的文档中说有这个方法,但是在2。5里没有
msvcrt.setmode(sys.stdout.fileno(),os.O_BINARY)
import sys
import msvcrt
import os
import cgi
#msvcrt.setmode(sys.stdout.fileno(),os.O_BINARY)
pic = open('.\\images\\winxp.gif','rb')
print 'Content-Type: image/gif \n\n'
print
picdata = pic.read()
sys.stdout.write(picdata)
pic.close()