2011-03-08 53 views
0

我开始与谷歌应用程序引擎,并试图一些快速learning.I过这个问题,它不会对我的地方发展environment.Here发生是偶然的代码谷歌AppEngine上不打印数组值

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 

任何人都可以请提供一些想法,为什么会这样?

+1

当您使用logging.debug()而不是打印时,这也会发生吗? – 2011-03-08 22:16:06

回答

0

我通过解决这个问题我自己

相反print命令,我们必须使用sys.stdout.write('text to print')

您需要import sys为上述工作得到了。

+0

它有可能是与标准输出是什么...可能是应用程序引擎中的一个错误,它无法识别'print'的输出需要去哪里... – Rupin 2011-03-10 06:35:02

0

我无法解释为什么开发服务器和生产之间的行为不同,但在Web应用程序中,如果您只是在没有首先发送HTTP标头的情况下将stdout标记为print,则应该期望您的输出将会得到错位。你至少应该在任何其他输出之前打印“\ r \ n”,尽管不使用某种类型的wsgi框架无论如何都是挫败感。

+0

我已经把下面的代码,仍然没有outputs.its一个空白的屏幕上的现场环境,但本地主机打印很好'print'Content-Type:text/plain'loveQuotes = [] loveQuotes.append(“Test1 “) loveQuotes.append(” Test2的 “) loveQuotes.append(” Test3的 “) loveQuotes.append(” TEST4" ) 打印loveQuotes [1]' – Rupin 2011-03-10 05:16:35