谷歌appengine不打印数组值

时间:2011-03-08 21:50:00

标签: python arrays google-app-engine random

我开始使用谷歌应用引擎,并尝试了一些快速学习。我偶然发现了这个问题,这在我的本地开发环境中没有发生。这是代码

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

任何人都可以请我告诉我为什么会这样?

2 个答案:

答案 0 :(得分:0)

我无法解释为什么开发服务器和生产之间的行为有所不同,但是在Web应用程序中,如果你只是在没有先发送HTTP标头的情况下将print填充到stdout,你应该期望你的输出是会被破坏。你应该至少在任何其他输出之前打印“\ r \ n”,尽管不使用某种wsgi框架无论如何都会让人感到沮丧。

答案 1 :(得分:0)

我自己解决了这个问题

我们必须使用print

而不是sys.stdout.write('text to print')命令

您需要import sys才能实现上述目标。