我从googleappengine开始尝试快速学习,但我偶然发现了这个问题,这个问题在我的本地开发中没有出现环境。这里是密码吗
import random, math
random.seed()
quotesArray=[]
quotesArray.append("This is a Test1")
quotesArray.append("This is a Test2")
quotesArray.append("This is a Test3")
quotesArray.append("This is a Test4")
quotesArray.append("This is a Test5")
x = int(math.floor(random.random()*343)+1)
print quotesArray[0]+" "+str(x)
在我的开发环境中,输出是
^{pr2}$在现场的输出是
45
有谁能告诉我为什么会这样吗?在
我自己解决了这个问题
代替
print
命令,我们必须使用sys.stdout.write('text to print')
您需要
import sys
才能使上述操作正常工作。在我无法解释为什么dev服务器和产品之间的行为是不同的,但是在web应用程序中,如果您在没有首先发送HTTP头的情况下简单地向stdout发送
print
内容,那么您的输出将被破坏。您至少应该在任何其他输出之前打印“\r\n”,尽管无论如何,不使用某种wsgi框架会导致失败。在相关问题 更多 >
编程相关推荐