我开始使用谷歌应用引擎,并尝试了一些快速学习。我偶然发现了这个问题,这在我的本地开发环境中没有发生。这是代码
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)
在我的开发环境中,输出是
This is a Test1 45
在实际网站上输出
45
任何人都可以请我告诉我为什么会这样?
答案 0 :(得分:0)
我无法解释为什么开发服务器和生产之间的行为有所不同,但是在Web应用程序中,如果你只是在没有先发送HTTP标头的情况下将print
填充到stdout,你应该期望你的输出是会被破坏。你应该至少在任何其他输出之前打印“\ r \ n”,尽管不使用某种wsgi框架无论如何都会让人感到沮丧。
答案 1 :(得分:0)
我自己解决了这个问题
我们必须使用print
sys.stdout.write('text to print')
命令
您需要import sys
才能实现上述目标。