Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python google appengine不打印数组值_Python_Arrays_Google App Engine_Random - Fatal编程技术网

Python google appengine不打印数组值

Python google appengine不打印数组值,python,arrays,google-app-engine,random,Python,Arrays,Google App Engine,Random,我从google应用程序引擎开始,并尝试快速学习。我偶然发现了这个问题,这在我的本地开发环境中没有出现。下面是代码 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

我从google应用程序引擎开始,并尝试快速学习。我偶然发现了这个问题,这在我的本地开发环境中没有出现。下面是代码

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

有人能告诉我为什么会这样吗?

我无法解释为什么开发服务器和产品之间的行为有所不同,但是在web应用程序中,如果您只是
内容打印到stdout而不首先发送HTTP头,您应该预料到您的输出会被破坏。您至少应该在任何其他输出之前打印“\r\n”,尽管不使用某种wsgi框架会让您感到沮丧。

我自己找到了解决这个问题的方法

我们必须使用
sys.stdout.write('text to print')


您需要
导入sys
才能使上述内容正常工作。

当您使用logging.debug()而不是print时,是否也会发生这种情况?我确实输入了以下代码,但仍然没有输出..它在live环境中是一个空白屏幕,但是localhost可以很好地打印'print'内容类型:text/plain'loveQuotes=[]loveQuotes.append(“Test1”)loveQuotes.append(“Test2”)loveQuotes.append(“Test3”)loveQuotes.append(“Test4”)print loveQuotes[1]`它可能与标准输出的内容有关……可能是应用程序引擎中的一个错误,无法识别打印的输出需要去哪里。。。